ggboxplot - 未绘制图表的顶部

时间:2018-04-30 20:21:06

标签: r ggplot2 boxplot

我一直试图通过使用与stat_compare_means相关联的ggboxplot()函数来绘制一系列箱图 - 使用stat_compare_means() - 没有太大成功。当我不试图修正x轴和y轴的极限时,我能够绘制出我想要的一切。但是,我必须修复y轴的限制,以使我的箱形图在不同的区域/样本中具有可比性。当我确定这些限制时,我的情节的顶部被切断,我无法看到平均值比较'显着性水平。

我用来生成箱图而不固定y轴限制的代码如下:

p1 <- ggboxplot(temp3[which(temp3$Nucleus == "Bolivia"),], x = "Biome", y = 
"pH",
          color = "Biome", add = "jitter", shape = "Biome",
          palette = c("springgreen4", "blue", "gray50"))
p2 <- ggboxplot(temp3[which(temp3$Nucleus == "Brazil"),], x = "Biome", y = 
"pH",
                color = "Biome", add = "jitter", shape = "Biome",
                palette = c("springgreen4", "blue", "gray50"))
p3 <- ggarrange(p1 + stat_compare_means(comparisons=my_comparisons),
            p2 + stat_compare_means(comparisons=my_comparisons),
            labels = c("Bolivia", "Brazil"),
            ncol = 2, nrow = 1)

这就是我一直试图修复y轴的方法。限制所以我可以对我的所有箱图都有相同的限制:

p1 <- ggboxplot(temp3[which(temp3$Nucleus == "Bolivia"),], x = "Biome", y = 
"pH",
          color = "Biome", add = "jitter", shape = "Biome",
          palette = c("springgreen4", "blue", "gray50"))
p2 <- ggboxplot(temp3[which(temp3$Nucleus == "Brazil"),], x = "Biome", y = 
"pH",
                color = "Biome", add = "jitter", shape = "Biome",
                palette = c("springgreen4", "blue", "gray50"))
p1.1 <- ggpar(p1, ylim = c(3,9), ylab = "pH")
p2.1 <- ggpar(p2, ylim = c(3,9), ylab = "pH")
p3 <- ggarrange(p1.1 + stat_compare_means(comparisons=my_comparisons),
            p2.1 + stat_compare_means(comparisons=my_comparisons),
            labels = c("Bolivia", "Brazil"),
            ncol = 2, nrow = 1)

使用ggarrange()确实正确处理了轴,但现在我无法看到我在箱形图上的所有成对均值比较。我该怎么做才能解决这个问题?

非常感谢任何帮助。

谢谢,

佩德罗

0 个答案:

没有答案