我使用以下代码生成感兴趣的对比
Gene1.emmeans1 <- emmeans(Gene1.lm, pairwise ~ Treatment | Status)
Gene1.emmeans2 <- emmeans(Gene1.lm, pairwise ~ Status | Treatment, adjust="tukey")
Gene1.treatpval <- as.data.frame(Gene1.emmeans1$contrasts)
Gene1.statuspval <- as.data.frame(Gene1.emmeans2$contrasts)
> Gene1.treatpval
contrast Status estimate SE df t.ratio p.value
1 None - Treat1 Control -0.1951810 0.4243245 38 -0.4599806 0.64815130
2 None - Treat1 Subclinical 0.7600000 0.4382404 38 1.7342079 0.00198806
3 None - Treat1 Clinical -0.2054107 0.4243245 38 -0.4840888 0.63110121
> Gene1.statuspval
contrast Treatment estimate SE df t.ratio p.value
1 Control - Subclinical None -0.8213417 0.4382404 38 -1.8741807 0.160062190
2 Control - Clinical None 0.7792297 0.4382404 38 1.7780872 0.190553770
3 Subclinical - Clinical None 1.6005714 0.4382404 38 3.6522678 0.002203273
4 Control - Subclinical Treat1 0.1338393 0.4243245 38 0.3154173 0.946712730
5 Control - Clinical Treat1 0.7690000 0.4099364 38 1.8759008 0.159552669
6 Subclinical - Clinical Treat1 0.6351607 0.4243245 38 1.4968750 0.303748340
如何将 emmeans 中的显着 p 值添加到我的 ggplot 中?作为包含四舍五入 p 值的括号还是(最好)星号?这是许多失败的尝试之一:
ggplot(Gene1.means,
aes(x=Status, y=AvgRQ, fill=Treatment)) +
geom_bar(position=position_dodge(), stat="identity") +
geom_errorbar(aes(ymin=AvgRQ-se, ymax=AvgRQ+se), width=0.2, position=position_dodge(0.9)) +
ggtitle("Gene1") +
theme_classic() +
theme(plot.title = element_text(hjust=0.5)) +
scale_fill_grey(start = 0.25, end = 0.8, na.value = "red", aesthetics = "fill") +
ylab("Fold Change") +
xlab("Status") +
stat_pvalue_manual(
comparisons=Gene1.treatpval, y.position = 3.5,
label = "p.value",
position = position_dodge(0.8))
这是我用来创建 ggplot 的数据:
> Gene1means
Status Treatment Detector AvgRQ sd se
1 Control None Gene1 3.653349 2.1593373 0.8161528
2 Control Treat1 Gene1 2.562429 0.8453975 0.3195302
3 Subclinical None Gene1 2.445429 1.2227579 0.4621591
4 Subclinical Treat1 Gene1 4.066000 1.5334035 0.5795721
5 Clinical None Gene1 2.939667 1.0487113 0.4281346
6 Clinical Treat1 Gene1 3.252429 1.5754542 0.5954657
会话信息:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.5
> rstudioapi::versionInfo()
$version
[1] ‘1.2.5042’