this question之后,我试图进行框线图和成对比较,以再次显示重要性级别(仅对有意义的对),但是这次我要进行2个以上的组进行比较,并且要进行更复杂的构面。

我将在此处使用虹膜数据集进行说明。检查下面的MWE,在其中添加其他“处理”变量的地方。

library(reshape2)
library(ggplot2)
data(iris)
iris$treatment <- rep(c("A","B"), length(iris$Species)/2)
mydf <- melt(iris, measure.vars=names(iris)[1:4])
ggplot(mydf, aes(x=variable, y=value, fill=Species)) + geom_boxplot() +
stat_summary(fun.y=mean, geom="point", shape=5, size=4) +
facet_grid(treatment~Species, scales="free", space="free_x") +
theme(axis.text.x = element_text(angle=45, hjust=1))


这将产生以下图:

r - R ggplot2:具有显着性级别(超过2组:成对的kruskal.test和wilcox.test两对)的箱线图和多个构面-LMLPHP

想法是对“变量”组(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width)执行Kruskal-Wallis测试,并在它们之间进行成对的Wilcoxon测试,“物种”和“标准”定义的PER FACET “治疗”。

就像我之前的问题一样,它最有可能涉及更新注释。

换句话说,我想要执行与发布的this other question中相同的操作,但是要使用PER FACET。

尽管解决方案应该非常相似,但我还是感到非常困惑和困惑……任何帮助将不胜感激!谢谢!!

最佳答案

你可以试试

library(ggsignif)
ggplot(mydf,aes(x=variable, y=value)) +
  geom_boxplot(aes(fill=Species)) + # define the fill argument here
  facet_grid(treatment~Species) +
  ylim(0,15)+
  theme(axis.text.x = element_text(angle=45, hjust=1)) +
  geom_signif(test="wilcox.test", comparisons = combn(levels(mydf$variable),2, simplify = F)[-4],
              step_increase = 0.2)


r - R ggplot2:具有显着性级别(超过2组:成对的kruskal.test和wilcox.test两对)的箱线图和多个构面-LMLPHP

可以通过添加Kruskal.wallis

library(ggpubr)
stat_compare_means(test="kruskal.test")

关于r - R ggplot2:具有显着性级别(超过2组:成对的kruskal.test和wilcox.test两对)的箱线图和多个构面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46446392/

10-12 20:39