R 将统计值手册与填充=组相结合

R 将统计值手册与填充=组相结合,r,ggplot2,graphing,ggpubr,R,Ggplot2,Graphing,Ggpubr,您好,我正在尝试使用ggpubr包中的stat_pvalue_手册在我的图上显示一些emmeans和Tukey的后期测试的输出。我过去成功地使用过stat\u pvalue\u手册,但从未使用过fill=GROUP属性。这似乎引起了一些问题。复制此示例所需的包是tidyverse、ggpubr、rstatix和emmeans ToothGrowth$dose <- as.factor(ToothGrowth$dose) emmeans_tooth <- ToothGrowth %&g

您好,我正在尝试使用ggpubr包中的stat_pvalue_手册在我的图上显示一些emmeans和Tukey的后期测试的输出。我过去成功地使用过stat\u pvalue\u手册,但从未使用过fill=GROUP属性。这似乎引起了一些问题。复制此示例所需的包是tidyverse、ggpubr、rstatix和emmeans

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
emmeans_tooth <- ToothGrowth %>%
  group_by(supp) %>%
  emmeans_test(len ~ dose, p.adjust.method = "bonferroni")
ggplot(data = ToothGrowth, mapping = aes(x = supp, y = len, fill = dose)) +
  geom_bar(stat = "summary", fun = "mean", position = "dodge") +
  stat_pvalue_manual(data = emmeans_tooth, label = "{p.adj.signif}", y.position = c(30, 33, 25, 35, 38), hide.ns = TRUE)
ToothGrowth$dose%
emmeans_试验(len~剂量,p.adjust.method=“bonferroni”)
ggplot(数据=牙齿生长,映射=aes(x=支持,y=长度,填充=剂量))+
几何图形栏(stat=“summary”,fun=“mean”,position=“dodge”)+
统计值手册(data=emmeans\u tooth,label=“{p.adj.signif}”,y.position=c(30,33,25,35,38),hide.ns=TRUE)
这个结构在过去是有效的,但是现在有一个填充aes,它返回一个错误“error in FUN(X[[i]],…):object'dose'not found”。不知道那里发生了什么

我想这可能是因为emmeans的输出,因为我以前从未使用过它。但它也不适用于Tukey's。我还尝试将mapping=aes移动到geom,以避免stat\u pvalue\u手册继承这些美学

tension_L <- warpbreaks %>%
  filter(tension == "L")
tension_L_aov <- aov(breaks ~ wool, data = tension_L)
summary(tension_L_aov)
tukey_breaks <- tukey_hsd(tension_L_aov)
ggplot(data = warpbreaks) +
  geom_boxplot(mapping = aes(x = tension, y = breaks, fill = wool)) +
  stat_pvalue_manual(tukey_breaks, label = "{p.adj.signif}", y.position = 30, hide.ns = TRUE)
tension\u L%
过滤器(张力=“L”)
张力
stat.test <- ToothGrowth %>%
  group_by(supp) %>%
  t_test(len ~ dose) %>%
  adjust_pvalue(method = "bonferroni") %>%
  add_significance("p.adj")
stat.test <- stat.test %>%
  add_xy_position(x = "supp", dodge = 0.8)
stat.test
bxp <- ggboxplot(ToothGrowth, x = "supp", y = "len", color = "dose", palette = c("red", "blue", "green")) +
  stat_pvalue_manual(stat.test,  label = "p", tip.length = 0)
bxp