我已经学习了一些关于使用 ggpubr 的教程,我似乎已经掌握了它的窍门。然而,我不需要 ggline() 图,而只想要一个点和误差条图(即,我们使用 ggline 得到的结果,但没有线条)。我通常使用 ggplot 中的 geom_point() + geom_bar() 制作此图,但由于 ggpubr 有自己的绘图函数,我不确定如何使用 stat_compare_means() 和 stat_pvalue_manual() 将显着性指标添加到绘图类型中想要。
下面是我正在使用的代码,但我想制作它,以便获得与此处类似的图片:
# Line plot of mean +/-se
ggline(ToothGrowth, x = "dose", y = "len", add = "mean_se")+
stat_compare_means() + # Global p-value
stat_compare_means(ref.group = "0.5", label = "p.signif",
label.y = c(22, 29))
对于像我这样感兴趣的新手,这里有 ggpubr 上的两个很好的页面: http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/ https://www.datanovia.com/en/blog/how-to-add-p-values-to-ggplot-facets/
我尝试过使用 ggdotplot,但这更多的是散点图,而不是仅仅为每个条件的平均值给出一分。
ggpubr
适合快速绘图。但当谈到定制时,你迟早会达到极限。虽然有一些 hacky 方法,即操纵 ggplot
返回的 ggline
对象,但我建议使用 ggplot2
: 从头开始构建你的图
library(ggpubr)
#> Loading required package: ggplot2
library(ggplot2)
ggplot(ToothGrowth, aes(factor(dose), len)) +
stat_summary(geom = "errorbar", width = .1) +
stat_summary(geom = "point") +
theme_pubr() +
stat_compare_means() + # Global p-value
stat_compare_means(
ref.group = "0.5", label = "p.signif",
label.y = c(22, 29)
)