1

I made a chart of concentric circles using ggplot + geom_bar + polar_coord, and I am struggling with placing the annotations in the correct spot. Take the following code, modified from a previous question I asked and its satisfactory answer.

df <- data.frame(A=letters[1:12],
                 B=c(rep("Dim_1",4),rep("Dim_2",4),rep("Dim_3",4)),
                 C=c(rep("Ind_1",2),rep("Ind_2",2),rep("Ind_3",2),rep("Ind_2",2),rep("Ind_5",2),rep("Ind_6",2)))

ggplot(df, aes(factor(1), fill = C)) +
  geom_bar(width = 1, colour = NA) +                       
  stat_count(aes(yintercept = cumsum(rev(..count..))),     
             geom = "hline") +                             
  coord_polar()+
  annotate("text",label = "A", x = 1, y = 2.5,size=2)+
  annotate("text",label = "B", x = 1, y = 3.5,size=2)

Here is what I get:

This is what I get

The problem is placement. I would like to place the annotate text around the circle. But since I created the chart from a geom_bar of 1 observation, I can move the texts only along the vertical axis.

How do I freely place my annotations in the chart? Many thanks in advance.

NBK
  • 887
  • 9
  • 20

1 Answers1

0

Don't clearly get the question but...annotate freely with geom_text instead as follows:

    ggplot(df, aes(factor(1), fill = C)) +
  geom_bar(width = 1, colour = NA) +                       
  stat_count(aes(yintercept = cumsum(rev(..count..))),     
             geom = "hline") +                             
  coord_polar()+
  geom_text(label="A",x=1.2,y=2.5)+
  geom_text(label="B",x=1.5,y=3.5)

This gives: enter image description here

You can edit as you wish.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • You're right. More straighforward than I thought. Since the x & y placements make intuitive sense for the bar chart but not the concentric circles chart, you may want to consider explaining how these placements map after the coord_polar conversion. – NBK Dec 28 '18 at 19:20
  • Hi, I've looked at the documentation of both functions. Not really sure to be honest. I thought it had to do with the lack of an `aes` mapping to `annotate` but not really sure. Hopefully an expert can help explain why. – NelsonGon Dec 29 '18 at 05:20