Home > Net >  geom_bar coord_polar labels with lines
geom_bar coord_polar labels with lines

Time:12-02

I am trying to label the series of concentric circles below with the labels from C in the data frame

I am aware that I could use something like geom_text_repel but I cannot seem to get it to work.

In addition, I cannot seem to get rid of the tick marks on the upper left.

enter image description here

df <- data.frame(C=c(rep("The macro-environment",4),rep("The industry",4),rep("Competitors",4),rep("The organisation",4)))

ggplot(df, aes(factor(1), fill = C))  
  geom_bar(width = 1, colour = NA, show.legend = FALSE, alpha = .8)      
  coord_polar()  
    labs(
        x = "",
        y = ""
    )  
    scale_fill_manual(values = c("#289045", "#beddc7", "#d4dfe9", "#286291"))  
    theme(axis.ticks.x = element_blank(),
        axis.ticks.y = element_blank())  
    theme_minimal()

CodePudding user response:

You could do:

ggplot(df, aes(factor(1), fill = C))  
  geom_bar(width = 1, colour = NA, show.legend = FALSE, alpha = .8)   
  geom_text(stat = 'count', aes(label = C), size = 6,
            position = position_stack(vjust = 0.5),
            vjust = c(0.5, 0.5, 0.5, 2))  
  coord_polar(start = pi)  
  labs(x = NULL, y = NULL )  
  scale_fill_manual(values = c("#289045", "#beddc7", "#d4dfe9", "#286291"))  
  theme_void()

enter image description here

CodePudding user response:

A second option would be to add your labels as curved labels using the geomtextpath package:

library(ggplot2)
library(geomtextpath)

ggplot(df, aes(factor(1), fill = C))  
  geom_bar(width = 1, colour = NA, show.legend = FALSE, alpha = .8)  
  geom_textpath(aes(x = .5, label = C, group = C),
    stat = "count", position = position_stack(vjust = .5),
    vjust = 1
  )  
  coord_polar()  
  labs(
    x = "",
    y = ""
  )  
  scale_fill_manual(values = c("#289045", "#beddc7", "#d4dfe9", "#286291"))  
  theme_void()

enter image description here

  • Related