在 grid.draw 内组合多个图时,GGPlot 注释被推离页面比例

GGPlot annotation gets pushed off page scale when combining multiple plots within grid.draw

我有 5 个不同组的 5 个地块。我想指出特定时间点的统计显着差异。我使用 annotate() 在时间点上方的各个图中放置星号。但是,当我将所有图组合在一起制作一个图形时,星号会被推离图。看起来是 y 尺度未固定的问题。我会提供尽可能多的数据。第一段代码是针对其中一个组的。 5 个组的图看起来都比较相似。第二位是我用来组合绘图的数据框。单独附上一个地块的图片,然后将所有地块组合在一起。多个图上应该有多个星号

ggplot(data,aes(X,Y,group=Group,color=Group))+
  theme_bw()+
  theme(panel.grid.major=element_line(color="white",size=.1))+
  theme(panel.grid.minor=element_line(color="white",size=.1))+
  geom_point(stat="summary")+
  geom_errorbar(stat="summary",fun.data=mean_se,width=0.25)+
  geom_line(stat="summary")+
  scale_color_manual(labels = c("C", "T"),values=c("black", "red"))+
  theme(axis.title.y = element_text(vjust=2.5))+
  annotate("text", x=5, y=3, label= "*",size=10)

grid.newpage()

grid.draw(rbind(ggplotGrob(plotanimal1), 
            ggplotGrob(plotanimal2), 
            ggplotGrob(plotanimal3), 
            ggplotGrob(plotanimal4), 
            ggplotGrob(plotanimal5)))

您可以使用 geom_pointshape = 42 来制作星号。这样,ggplot 将自动修复 y 轴值本身。您需要将美学设置为与 annotate 相同的值。所以而不是

 annotate("text", x=5, y=3, label= "*",size=10)

你可以做到

 geom_point(aes(x=5, y=3), shape = 42, size = 2)

您是否尝试过使用包 patchwork 来组织绘图?它通常比 grid.draw

效果更好