英文:
P values missing in faceted ggviolin plot (R, ggplot2)
问题
我有这段代码:
library(ggplot2)
library(ggpubr)
df <- ToothGrowth
df$dose <- as.factor(df$dose)
df$group <- c(rep(c("grp1", "grp2"), 5), rep(c("grp1", "grp2", "grp3"), 6),
rep(c("grp1", "grp2"), 6), rep(c("grp1", "grp2", "grp3"), 6), "grp2", "grp3")
plot <- ggviolin(df, x = "group", y = "len", fill = "group",
width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = 'dose') +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
stat_compare_means(comparisons = list(c("grp1","grp2"),c("grp2","grp3")),
label = "p.format")
在第一个分面中,比较grp1和grp2的p值丢失,尽管可以计算出来。我认为这是因为grp3没有数据,但如何让它显示出来呢?重要的是,我的真实数据有更多的分面,所以我希望找到一个适用于所有分面的解决方案,而不是对特定分面进行调整,我已经找到了解决方案。谢谢。
英文:
I have this code:
library(ggplot2)
library(ggpubr)
df <- ToothGrowth
df$dose <- as.factor(df$dose)
df$group <- c(rep(c("grp1", "grp2"), 5), rep(c("grp1", "grp2", "grp3"), 6),
rep(c("grp1", "grp2"), 6), rep(c("grp1", "grp2", "grp3"), 6), "grp2", "grp3")
plot <- ggviolin(df, x = "group", y = "len", fill = "group",
width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = 'dose') +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
stat_compare_means(comparisons = list(c("grp1","grp2"),c("grp2","grp3")),
label = "p.format")
In the first facet, the p value comparing grp1 and grp2 is missing, although it can be calculated. I think this is because grp3 has no data, but how can I get it to show up? Importantly, my real data have many more facets, so I would like a solution that works across facets rather than making adjustments to specific facets, which I have found solutions for. Thank you.
答案1
得分: 1
不确定这是否回答了您的问题。它显示了缺失的比较。
plot <- ggviolin(df,
x = "group", y = "len", fill = "group",
width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = "dose"
) +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
stat_compare_means(
comparisons = list(c("grp1", "grp2"), c("grp2", "grp3")),
label = "p.format"
) +
stat_compare_means(
comparisons = list(c("grp1", "grp2")),
label = "p.format"
)
英文:
Not sure if this answers your question. It shows the missing comparisons.
plot <- ggviolin(df,
x = "group", y = "len", fill = "group",
width = 0.8, alpha = 0.5, draw_quantiles = c(0.25, 0.5, 0.75), facet.by = "dose"
) +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
stat_compare_means(
comparisons = list(c("grp1", "grp2"), c("grp2", "grp3")),
label = "p.format"
) +
stat_compare_means(
comparisons = list(c("grp1", "grp2")),
label = "p.format"
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论