stat_compare_means多组函数比较

inn6fuwd  于 2023-06-03  发布在  其他
关注(0)|答案(1)|浏览(402)

我正试着用箱形图绘制我的数据,并进行平均值的比较。这是我的数据。

structure(list(Time = structure(c(1L, 1L, 1L, 2L, 2L, 
2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 
3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 
3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L), levels = c("4", "5", "6", "7", 
"8"), class = "factor"), Group = c("16S", "16S", "16S", "16S", 
"16S", "16S", "16S", "16S", "16S", "16S", "16S", "16S", "16S", 
"16S", "16S", "arabinan", "arabinan", "arabinan", "arabinan", 
"arabinan", "arabinan", "arabinan", "arabinan", "arabinan", "arabinan", 
"arabinan", "arabinan", "arabinan", "arabinan", "arabinan", "skrob", 
"skrob", "skrob", "skrob", "skrob", "skrob", "skrob", "skrob", 
"skrob", "skrob", "skrob", "skrob", "skrob", "skrob", "skrob"
), Cq = c(11.13063931, 11.15984429, 9.764765629, 11.11921187, 
11.23636015, 11.3220628, 13.57819885, 13.49193753, 12.10672097, 
14.44320106, 14.37544944, 8.47863564, 16.01102045, 12.85357539, 
13.86110729, 21.62921058, 19.90989407, 21.0387778, 19.30354718, 
19.63518702, 19.4119743, 17.06448567, 16.95057763, 16.9692573, 
14.96970081, 15.02672693, 14.98234806, 15.01538052, 14.75905977, 
14.78030967, 13.84361199, 14.17159598, 14.489989, 14.8658601, 
14.90056887, 14.66559991, 15.89827103, 15.49736892, 15.70061002, 
21.39779052, 21.39592915, 21.59904463, 22.61395674, 22.55805188, 
22.46050134), Starting.Quantity..SQ. = c(0.031695618, 
0.031098635, 0.07712746, 0.031932316, 0.029587343, 0.027981628, 
0.006440738, 0.006812815, 0.016788261, 0.003667335, 0.003832726, 
0.178184848, 0.001321415, 0.010323517, 0.005357244, 0.015890751, 
0.04604206, 0.02289834, 0.067002457, 0.054572433, 0.062654818, 
0.267772272, 0.287325838, 0.284024058, 0.978747868, 0.944815297, 
0.971118645, 0.951471738, 1.114997127, 1.100432813, 2.939653152, 
2.402067713, 1.974418707, 1.566470577, 1.533346405, 1.772052794, 
0.829527162, 1.06179707, 0.936892888, 0.02806249, 0.028094673, 
0.024791682, 0.013270704, 0.013735494, 0.014585847)), row.names = c(NA, 
-45L), class = "data.frame")

下面是我使用的代码

libray(ggplot2)
my_data <- read.csv("data", header = TRUE)
boxplot <- ggplot(my_data, aes(factor(Time), Starting.Quantity..SQ., fill = Group)) + facet_wrap(~Group) + geom_boxplot()
boxplot + stat_compare_means(comparisons = list(c("4", "5"), c("4", "6"), c("4", "7"), c("4", "8")), method="t.test", label="p.signif")

我想知道为什么只有第一组的统计分析,而不是所有的?
谢谢你的帮助。

uemypmqf

uemypmqf1#

您可以将您的fill美学分配给您正在使用的geom函数,如geom_boxplot

library(ggplot2)
library(ggpubr)
ggplot(my_data, aes(factor(Time), Starting.Quantity..SQ.)) + 
  geom_boxplot(aes(fill = Group)) +
  facet_wrap(~Group) + 
  stat_compare_means(comparisons = list(c("4", "5"), c("4", "6"), c("4", "7"), c("4", "8")), method="t.test", label="p.signif")

创建于2023-05-31带有reprex v2.0.2

相关问题