首页 > 解决方案 > 我可以在 ggplot2 中使用 Annotate 来填充我的小提琴图吗?

问题描述

我使用 rtruncnorm 和一组数据制作了小提琴图并对其进行了注释。这是我的情节代码:

 ggplot(g) + 
      annotate(geom = "rect", xmin = -Inf , xmax = Inf , ymin = 0, ymax = 1, fill = "red", alpha= 0.4) +
      annotate(geom = "rect", xmin = -Inf , xmax = Inf , ymin = 1, ymax = max(g$PGR), fill = "green", alpha= 0.4) + 
      geom_violin(aes(x=1, y=PGR), fill=NA , color="darkred") + 
      geom_boxplot(aes(x=1, y=PGR) , width = 0.01) +
      theme(axis.title.x=element_blank(),
            axis.text.x=element_blank(),
            axis.ticks.x=element_blank())

并收到了这个情节: 小提琴情节

在此处输入图像描述

我想使用注释来填充小提琴图制作的形状。所以我只想对“小提琴”内的区域进行注释。有什么建议么?线索?

谢谢你的帮助 :)

标签: rggplot2annotateviolin-plot

解决方案


推荐阅读