R ggplot2多箱图统计

时间:2019-03-12 11:48:50

标签: r ggplot2

我有一个情节,类似于图片中的情节(取自here):

library(ggplot2)

# create fake dataset with additional attributes - sex, sample, and temperature
x <- data.frame(
 values = c(runif(100, min = -2), runif(100), runif(100, max = 2), runif(100)),
 sex = rep(c('M', 'F'), each = 100),
 sample = rep(c('sample_a', 'sample_b'), each = 200),
 temperature = sample(c('15C', '25C', '30C', '42C'), 400, replace = TRUE)
)

# compare different sample populations across various temperatures
ggplot(x, aes(x = sample, y = values, fill = sex)) +
geom_boxplot() +
facet_wrap(~ temperature)

enter image description here

我希望每个样本(sample_a / b)在F组和M组之间进行统计比较(wilcoxon)与其他预期数据。

我尝试将预期数据添加为F&M样本旁边的另一个箱形图或数据上的点-但对于这些选项中的任何一个,我都没有成功地弄清楚如何使用ggplot2统计层进行统计分析。 / p>

0 个答案:

没有答案