在 ggplot2 中,如何在编辑的图中显示 emmeans 对比显着的 p 值

问题描述

我一直在将我的箱线图复制到 word 并手动输入重要的 p 值。当我使用推荐的代码 stat_compare_means(comparisons = my_comparisons,label.y = c(85,90,95) 时,我得到的数字不准确。我要找的是括号来自 emmeans 对比结果的最后一行代码中的显着 p=values emmeans(lmer2,pairwise ~ Year | transect)。我曾尝试使用“对比”一词而不是“比较”

这是我运行的源代码

https://rpubs.com/mberry1/713185

示例代码

plots     transect  Year Total
<chr>        <dbl> <dbl> <dbl>
1 D11_norTH        1     1   46 
2 D11_SOUTH        1     1   56.
3 R27_norTH        1     1   34 
4 R27_SOUTH        1     1   38 
5 R28_norTH        1     1   50 
6 R28_SOUTH        1     1   34 
7 D13_norTH        2     1   60 
8 D13_SOUTH        2     1   10 

glm_test$year <- factor(glm_test$year,levels = c(1,2,3),labels = c("2018","2019","2020"))


glm_test$transect <- factor(glm_test$transect,labels = c("Lower Meadow","Middle Meadow","Upper 
Meadow"))
summary(glm_test)

#运行线性模型,覆盖为因变量,年份为 #独立变量对于情节,说明 + (1| plot),这使它成为#repeated measure

lmer2 <- lmer(cover ~ as.factor(year) * as.factor(transect) + (1|plot),data = glm_test)
anova(lmer2)

#post Hoc 比较

emmeans(lmer2,list(pairwise ~ year),adjust = "tukey")  

#如果有交互,你的代码就是这个

emmeans(lmer2,pairwise ~ year | transect)
                              

横断面 = 上草甸的对比结果:

|对比|估计|东南 df| t.ratio| p值| | ---------- | -------- | ----- | ------ | ------ | |2018 - 2019 | 27.500 |7.15 38| 3.848 | 0.0013 | |2018 - 2020 | 20.000 |7.15 38| 2.798 | 0.0214 | |2019 - 2020 | -7.500 |7.15 38| -1.049 | 0.5509 | 自由度方法:kenward-roger P 值调整:比较 3 个估计值族的 tukey 方法

#可视化数据

ggBoxplot(glm_test,x = "year",y = "cover",title = "Total % Cover of 
Upland 
Species Across All Years",ylab = " % Cover UPL Species",color = "transect",ggtheme = theme_gray(base_size = 14))+
stat_compare_means(comparisons = my_comparisons,95))+
stat_compare_means(label.y = 110)

enter image description here

上面的箱线图对我来说没有意义,我在上面的 emmenas 对比中寻找显着的 p 值。下面的箱线图是我在 word 中手工放置的 p 值

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)