ggplot 上的符号而不是 p 值数字
Symbols instead of p-value numbers on ggplot
我创建了以下数据和图表。如何用符号替换 p 值?
- 如果 p 值大于 0.05 - 不显示,
- 如果 p 值介于 0.01 到 0.05 之间,则显示 *
- 如果 p 值小于 0.01,则显示 **
有配套吗?谁能举个例子?
我发现我可以在 stat_compare_means 中添加 "label = "p.signif",但它显示 "ns" 而不是不显示。
df <- data.frame("Class" = c("A","A","A","A","A","A","A","A","A",
"B","B","B","B","B","B","B","B","B",
"C","C","C","C","C","C","C","C","C"),
"Subject" = c("Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing",
"Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing",
"Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing"),
"Score" = c(round(runif(27,0,100))))
library("ggplot2")
comp <- list (c("A","B"), c("A", "C"), c("B", "C"))
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test", comparisons = comp)
我们可以在stat_compare_means
中使用symnum.args
,并根据需要分配cutpoints
和symbols
。
library(ggplot2)
library(ggpubr)
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test", comparisons = comp,
symnum.args = list(cutpoints = c(0, 0.01, 0.05, Inf),
symbols = c("**", "*", "")))
显然,您使用的是 functions
或 ggpubr
软件包。添加 label = "p.signif", hide.ns = TRUE
将执行:
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test",
label = "p.signif", hide.ns = TRUE,
comparisons = comp)
我创建了以下数据和图表。如何用符号替换 p 值?
- 如果 p 值大于 0.05 - 不显示,
- 如果 p 值介于 0.01 到 0.05 之间,则显示 *
- 如果 p 值小于 0.01,则显示 **
有配套吗?谁能举个例子?
我发现我可以在 stat_compare_means 中添加 "label = "p.signif",但它显示 "ns" 而不是不显示。
df <- data.frame("Class" = c("A","A","A","A","A","A","A","A","A",
"B","B","B","B","B","B","B","B","B",
"C","C","C","C","C","C","C","C","C"),
"Subject" = c("Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing",
"Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing",
"Math","Math","Math","Reading","Reading","Reading","Writing","Writing","Writing"),
"Score" = c(round(runif(27,0,100))))
library("ggplot2")
comp <- list (c("A","B"), c("A", "C"), c("B", "C"))
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test", comparisons = comp)
我们可以在stat_compare_means
中使用symnum.args
,并根据需要分配cutpoints
和symbols
。
library(ggplot2)
library(ggpubr)
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test", comparisons = comp,
symnum.args = list(cutpoints = c(0, 0.01, 0.05, Inf),
symbols = c("**", "*", "")))
显然,您使用的是 functions
或 ggpubr
软件包。添加 label = "p.signif", hide.ns = TRUE
将执行:
ggplot(data = df, aes(x = Class, y = Score, color = Subject)) +
facet_wrap(~Subject) +
geom_violin(trim = FALSE) +
stat_compare_means(aes(group = Subject), method = "t.test",
label = "p.signif", hide.ns = TRUE,
comparisons = comp)