r - 构面中的重要性注释
问题描述
我试图以成对的方式注释下面的图 - 在每个方面比较对应samples
的variable
. 本质上是比较CTR
从 pos
到CTR
从neg
等等。我似乎无法让它工作。
这是我的数据和图表:
library(ggpubr)
#data.frame
samples <- rep(c('LA', 'EA', 'CTR'), 300)
variable <- sample(c('pos', 'neg'), 900, replace = T)
stim <- rep(c('rp','il'), 450)
population <- sample(c('EM','CM','TEMRA'), 900, replace = T)
values <- runif(900, min = 0, max = 100)
df <- data.frame(samples, variable, stim, population, values)
#test and comparisons
test_comparisons <- list(c('neg', 'pos'))
test <- compare_means(values ~ variable, data = df, method = 'wilcox.test',
group.by = c('samples', 'stim', 'population'))
#plot
ggplot(aes(x= variable, y = values, fill = samples), data = df) +
geom_boxplot(position = position_dodge(0.85)) +
geom_dotplot(binaxis='y', stackdir='center', position =
position_dodge(0.85), dotsize = 1.5) +
facet_grid(population ~ stim, scales = 'free_x') +
stat_compare_means(comparisons = test_comparisons, label = 'p.signif') +
theme_bw()
这只会在 pos 和 neg 之间的每个方面产生 1 个比较,而不是 3...我做错了什么?
解决方案
您可以使用以下代码:
samples <- rep(c('LA', 'EA', 'CTR'), 300)
variable <- sample(c('pos', 'neg'), 900, replace = T)
stim <- rep(c('rp','il'), 450)
population <- sample(c('EM','CM','TEMRA'), 900, replace = T)
values <- runif(900, min = 0, max = 100)
df <- data.frame(samples, variable, stim, population, values)
#test and comparisons
test_comparisons <- list(c('neg', 'pos'))
test <- compare_means(values ~ variable, data = df, method = 'wilcox.test',
group.by = c('samples', 'stim', 'population'))
#plot
ggplot(aes(x= variable, y = values, fill = samples), data = df) +
geom_boxplot(position = position_dodge(0.85)) +
geom_dotplot(binaxis='y', stackdir='center', position =
position_dodge(0.85), dotsize = 1.5) +
facet_grid(population ~ stim+samples, scales = 'free_x') +
stat_compare_means(comparisons = test_comparisons, label = 'p.signif') +
theme_bw()
希望这能解决您的问题
推荐阅读
- python-3.x - 函数内的闭包
- python - 一个入口名称具有多个规则
- html - Bootstrap Carousel Stacking/Overlaying divs/items
- python - 如何使用 Sympy 计算 lambda 表达式的导数?
- reactjs - 如何根据所选语言使用调度和 PATCH 请求更新产品属性?
- python - Python中的SQL解析
- excel - 如何根据excel中的另一行值连接行值?
- php - 无法上传大文件 -> 错误 413 或 ERR_CONNECTION_RESET
- android - Android计费客户端导致内存泄漏
- node.js - DiscordJS:如何在当前在线频道中选择随机用户?