r ggplot - 使用 coord_polar 在同心圆图表中放置注释

r ggplot - placing annotations in concentric circles chart using coord_polar

我使用 ggplot + geom_bar + polar_coord 制作了一个同心圆图表,我正在努力将注释放在正确的位置。采取以下代码,修改自 我问及其满意的答案。

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)

这是我得到的:

问题是位置。我想在圆圈周围放置 annotate 文本。但由于我是根据 geom_bar 的 1 次观察创建图表的,所以我只能沿垂直轴移动文本。

如何在图表中自由放置注释?非常感谢。

没有清楚地理解问题但是......用geom_text自由注释,而不是如下:

    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)

这给出:

您可以随意编辑。