通过分组变量绘制pvalue信息以进行均值比较 [英] Plot pvalue information for mean comparisons by grouping variable
问题描述
我整理了一个图以分别查看组,但现在想在图中包含均值成对比较的显着性水平.虽然我可以在图外进行比较,但我想知道将比较包括在图中的最有效方法是什么?
I've put together a plot to view groups separately but now want to include significance levels for mean pairwise comparison in the plot. While I can do the comparison outside of the plot I'm wondering what the most efficient way of including the comparison in the plot would be?
当前图
library(tidyverse)
dsub <- diamonds[ sample(nrow(diamonds), 10000), ]
dsub <- dsub %>%
filter(clarity %in% c('VS2', 'VS1', 'VVS2'))
ggplot(dsub, aes(x = cut, y = carat, fill = clarity)) +
geom_boxplot(outlier.size = 0) +
geom_point(pch = 21, position = position_jitterdodge())
现在,我想在 clear
的所有级别之间的 cut
变量的每个级别中添加比较.>变量.我更喜欢使用 ggpubr
,但看不到可以在哪里实现.
Now I want to add the comparisons within each level of the cut
variable between all levels of the clarity
variable. I prefer using ggpubr
but couldn't see where this could be achieved.
推荐答案
已进行编辑,以考虑到OP的输出偏好设置
啊……好吧,我克服了 rstatix
不遵守因子和的顺序这一事实,至少可以为您节省一堆垂直空间并整理东西.ggpubr
希望将其组作为字符而不是因素.
Ahhhh... okay well let me at least save you a bunch of vertical space and neaten things up by overcoming the fact that rstatix
doesn't honor the order of your factors and ggpubr
wants its groups as character not factor.
library(ggplot2)
library(dplyr)
dsub <- diamonds[ sample(nrow(diamonds), 10000), ]
dsub <- dsub %>%
filter(clarity %in% c('VS2', 'VS1', 'VVS2'))
dsub <- droplevels(dsub)
dsub_stats <-
dsub %>%
group_by(cut) %>%
rstatix::wilcox_test(carat~clarity) %>%
mutate(group1 = factor(group1,
ordered = TRUE,
levels = c("VS2", "VS1", "VVS2"))) %>%
arrange(cut, group1) %>%
mutate(group1 = as.character(group1)) %>%
rstatix::add_xy_position(x='cut')
ggpubr::ggboxplot(dsub, x = "cut", y = "carat",
color = "clarity",
add='jitter') +
ggpubr::stat_pvalue_manual(dsub_stats,
label = "p.adj.signif",
tip.length = 0.01)
由 reprex软件包(v0.3.0)
Created on 2020-09-24 by the reprex package (v0.3.0)
这篇关于通过分组变量绘制pvalue信息以进行均值比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!