如何添加这样的注释?

时间:2019-03-29 20:08:51

标签: r ggplot2

enter image description here

如何在ggplot中添加这样的注释?我需要添加文本(CV,网络),条形图以及那些星星。

1 个答案:

答案 0 :(得分:4)

我希望您可以将此示例转移到您的数据集中:

ggplot() + geom_point(aes(x = 1:10, y = 1:10)) + 
  geom_segment(aes(x=0,y=11,xend=5,yend=11)) +  geom_segment(aes(x=0,y=11,xend=0,yend=10.5)) + geom_segment(aes(x=5,y=11,xend=5,yend=10.5)) + ##bracket 1
  geom_segment(aes(x=5.5,y=11,xend=10,yend=11)) +  geom_segment(aes(x=5.5,y=11,xend=5.5,yend=10.5)) + geom_segment(aes(x=10,y=11,xend=10,yend=10.5)) + #bracket 2
  geom_text(aes(x=2.5,y=11.5,label="Group 1")) + geom_text(aes(x=7.75,y=11.5,label="Group 2")) + #add labels
  coord_cartesian(ylim = c(0, 10), clip="off")+theme(plot.margin = unit(c(4,1,1,0), "lines")) #change plot margins

enter image description here