【发布时间】:2019-03-08 14:11:04
【问题描述】:
我在 R 中创建了一个条形图,现在我尝试将显着差异添加到条形图中。
我尝试使用 ggsignif 包中的 geom_signif 和 ggpubr 包中的 stat_compare_means(基于这些建议/示例:Put stars on ggplot barplots and boxplots - to indicate the level of significance (p-value) 或 https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html)
我只能在使用geom_signif 时添加显着性水平并选择https://cran.r-project.org/web/packages/ggsignif/vignettes/intro.html 中的参数。
这是我想要得到的示例:
这就是我得到的:
所以当我想添加星号时,它会从条形图中移动条形。不知道怎么改。。。
这是我写的部分内容:
bargraph = ggplot(dataPlotROI, aes(x = ROI, y=mean, fill = Group))
bargraph +
geom_bar(position = position_dodge(.5), width = 0.5, stat = "identity") +
geom_errorbar(position = position_dodge(width = 0.5), width = .2,
aes(ymin = mean-SEM, ymax = mean+SEM)) +
geom_signif(y_position = c(4.5,10,10), xmin=c(0.85,0.85,4.3), xmax = c(5,4,7.45),
annotation=c("***"), tip_length = 0.03, inherit.aes = TRUE) +
facet_grid(.~ROI, space= "free_x", scales = "free_x", switch = "x")
这是dput(dataPlotROI)的输出:
> Dput <- dput(dataPlotROI)
structure(list(Group = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("1",
"2"), class = "factor"), ROI = structure(c(1L, 2L, 3L, 1L, 2L,
3L), .Label = c("LOT", "MO", "ROT"), class = "factor"), mean = c(2.56175803333696,
7.50825658538044, 3.34290874605435, 2.41750375190217, 6.90310020776087,
3.03040666678261), SD = c(1.15192431061913, 4.30564383354597,
2.01581544982848, 1.11404900115086, 3.35276625079825, 1.23786817391241
), SEM = c(0.120096411333424, 0.448894400545147, 0.210163288684092,
0.11614763735292, 0.349550045127766, 0.129056678481624)), class = "data.frame", row.names = c(NA,
-6L))
> Dput
Group ROI mean SD SEM
1 1 LOT 2.561758 1.151924 0.1200964
2 1 MO 7.508257 4.305644 0.4488944
3 1 ROT 3.342909 2.015815 0.2101633
4 2 LOT 2.417504 1.114049 0.1161476
5 2 MO 6.903100 3.352766 0.3495500
6 2 ROT 3.030407 1.237868 0.1290567
有谁知道我做错了什么以及如何解决它?
谢谢!
【问题讨论】:
-
您能否将
dput(dataPlotROI)的输出包含在您的问题中? -
@Z.Lin 我添加了输出
标签: r ggplot2 significance