我正在尝试使用 ggpubr 包在 boxplot 上添加标签。这是我使用的代码:
library(ggplot2)
library(ggpubr)
compare_means(len ~ supp, data = ToothGrowth, method="t.test", paired=TRUE, group.by = "dose")
# Box plot facetted by "dose"
p1 <- ggboxplot(ToothGrowth, x = "supp", y = "len", xlab=F,
color = "supp", palette = "jco",
facet.by = "dose", add="mean", short.panel.labs = FALSE)
# Use only p as label.
p2 <- p1 + stat_compare_means(method = "t.test", paired = T, label = "p")
p2
以及样本数据(ToothGrowth)
15.5 VC 1.0
23.6 VC 2.0
18.5 VC 2.0
33.9 VC 2.0
25.5 VC 2.0
26.4 VC 2.0
32.5 VC 2.0
26.7 VC 2.0
21.5 VC 2.0
23.3 VC 2.0
29.5 VC 2.0
15.2 OJ 0.5
21.5 OJ 0.5
17.6 OJ 0.5
9.7 OJ 0.5
14.5 OJ 0.5
10.0 OJ 0.5
8.2 OJ 0.5
9.4 OJ 0.5
16.5 OJ 0.5
9.7 OJ 0.5
有什么方法可以将平均值作为文本添加(除了点使用:add="mean")
如果可能的话,我想将平均值文本放在来自“stat_compare_means”代码的“p=0.000”下方。
另外,有没有办法删除分组情节时自动生成的图例?
我想要制作的最终情节如下所示:
- 在箱线图上添加平均值作为文本
- 删除顶部的图例
提前致谢!