R语言 如何将数据点添加到具有p值的分组条形图

xuo3flqw  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(124)

我有一个问题,当我试图使我的条形图与本教程https://www.datanovia.com/en/blog/how-to-add-p-values-onto-a-grouped-ggplot-using-the-ggpubr-r-package/

library(ggpubr)
library(rstatix)
#data
df <- ToothGrowth
df$dose <- as.factor(df$dose)
head(df, 3)
#pvalue
stat.test <- df %>%
  group_by(dose) %>%
  t_test(len ~ supp) %>%
  adjust_pvalue(method = "bonferroni") %>%
  add_significance("p.adj")
stat.test

# Create a bar plot with error bars (mean +/- sd)
bp <- ggbarplot(
  df, x = "dose", y = "len", add = "mean_sd", 
  color= "supp", palette = c("#00AFBB", "#E7B800"),
  position = position_dodge(0.8)
) + geom_point()
# Add p-values onto the bar plots
stat.test <- stat.test %>%
  add_xy_position(fun = "mean_sd", x = "dose", dodge = 0.8) 
bp + stat_pvalue_manual(
  stat.test,  label = "p.adj.signif", tip.length = 0.01
)

# Move down the brackets using `bracket.nudge.y`
bp + stat_pvalue_manual(
  stat.test,  label = "p.adj.signif", tip.length = 0,
  bracket.nudge.y = -2
)

我试图添加数据点,但点无法与列对齐。
x1c 0d1x非常感谢您的帮助!

yzuktlbb

yzuktlbb1#

我终于找到了方法:

bp <- ggbarplot(
  df, x = "strains", y = "survival", add = "mean_sd", 
  fill= "condition", palette = c("#00AFBB", "#E7B800"),
  position = position_dodge(0.8)
) + 
geom_point(size=2,aes(col=condition), alpha=.5, position = position_dodge(0.8)) +   scale_color_manual(values = c("black", "black"))

非常感谢

相关问题