在分组图中使用 ggpubr 绘制 p 值会导致错误
Plotting p-values with ggpubr in grouped plot results in error
我正在用 ggplot2, which works fine. But if I am using stat_compare_means
from the ggpubr
package to add p-value 绘制一个 grouped dotplot
,它不会工作。当我在绘图环境之外使用 compare_means
时,它工作正常并且我得到了正确的 p-values
数据集(使用 compare_means(X1 ~ X5, data=titer_lung, method="t.test"
)。
我正在使用以下数据:
> titer_lung
X1 X2 X3 X4 X5
1 4.531479 NK mutIRFE_FB Lunge group1
2 4.068186 NK mutIRFE_FB Lunge group1
3 4.071882 NK mutIRFE_FB Lunge group1
4 4.117271 NK mutIRFE_FB Lunge group1
5 4.117271 NK mutIRFE_FB Lunge group1
6 4.462398 -NK mutIRFE_FB Lunge group2
7 4.643453 -NK mutIRFE_FB Lunge group2
8 4.556303 -NK mutIRFE_FB Lunge group2
9 4.724276 -NK mutIRFE_FB Lunge group2
10 4.491362 -NK mutIRFE_FB Lunge group2
11 3.903090 NK mutIRFErev_FB Lunge group3
12 4.342423 NK mutIRFErev_FB Lunge group3
13 4.113943 NK mutIRFErev_FB Lunge group3
14 4.653213 NK mutIRFErev_FB Lunge group3
15 4.230449 NK mutIRFErev_FB Lunge group3
16 4.556303 -NK mutIRFErev_FB Lunge group4
17 4.462398 -NK mutIRFErev_FB Lunge group4
18 4.230449 -NK mutIRFErev_FB Lunge group4
19 NA -NK mutIRFErev_FB Lunge group4
20 4.591065 -NK mutIRFErev_FB Lunge group4
21 4.230449 NK d3IDE mutIRFE Lunge group5
22 4.531479 NK d3IDE mutIRFE Lunge group5
23 4.812913 NK d3IDE mutIRFE Lunge group5
24 4.544068 NK d3IDE mutIRFE Lunge group5
25 4.342423 NK d3IDE mutIRFE Lunge group5
26 4.380211 -NK d3IDE mutIRFE Lunge group6
27 4.698970 -NK d3IDE mutIRFE Lunge group6
28 4.716003 -NK d3IDE mutIRFE Lunge group6
29 4.477121 -NK d3IDE mutIRFE Lunge group6
30 4.740363 -NK d3IDE mutIRFE Lunge group6
31 4.255273 NK d3IDE mutIRFErev Lunge group7
32 4.322219 NK d3IDE mutIRFErev Lunge group7
33 4.113943 NK d3IDE mutIRFErev Lunge group7
34 4.176091 NK d3IDE mutIRFErev Lunge group7
35 4.518514 NK d3IDE mutIRFErev Lunge group7
36 4.724276 -NK d3IDE mutIRFErev Lunge group8
37 4.462398 -NK d3IDE mutIRFErev Lunge group8
38 4.785330 -NK d3IDE mutIRFErev Lunge group8
39 4.431364 -NK d3IDE mutIRFErev Lunge group8
40 4.826075 -NK d3IDE mutIRFErev Lunge group8
通过使用以下代码,我得到了我正在寻找的情节:
titer_plot <- ggplot(titer_lung, aes(y=titer_lung$X1, x=titer_lung$X3,
fill=titer_lung$X2)) +
geom_dotplot(aes(fill = titer_lung$X2, color = titer_lung$X2),
trim = FALSE,
binaxis='y', stackdir='center', dotsize = 0.8,
position = position_dodge(0.8)
)+
stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median,
geom = "crossbar", width = 0.5, position = position_dodge(0.8)) +
scale_fill_manual(values = c("black", "white"))+
scale_color_manual(values = c("black", "black"))+
xlab("")+
ylab(expression('Viral titer/organ [log '[10]*']'))+
theme_classic()+
theme(text = element_text(size=10),
axis.text.x = element_text(size=10, angle = 90, hjust=1),
axis.text.y = element_text(size=10),
axis.title.y = element_text(size=10), legend.text = element_text(size=10),
legend.title=element_blank())+
titer_plot
当我想比较 group1 和 group2 以及 group3 和 group4 时,我写:
my_comparisons <- list(c("group1","group2"),c("group3","group4"))
titer_plot + stat_compare_means(comparisons=my_comparisons, label.y=0,
method = "t.test")
但随后我收到以下错误:
Removed 1 rows containing non-finite values (stat_signif).
Computation failed in stat_signif()
: missing value where TRUE/FALSE
needed
我想 NA
值应该没有问题,因为 compare_means
也没有问题。
我很高兴得到每一个帮助,谢谢!!!
问题是,不知道括号放在哪里(x-coordinates)
comparisons: A list of length-2 vectors. The entries in the vector are either the names of 2 values on the x-axis or the 2 integers that correspond to the index of the groups of interest, to be compared.
titer_plot + stat_compare_means(aes(group=X2), method = "t.test",) #specify the groups specifically
label.y=5
我不知道如何克服这个问题,但底层 geom_signif
有一个 "manual" 论点。所以我想你可以以某种方式将 compare_means(X1 ~ X5, data=titer_lung, method="t.test")
的输出提供给这个 geom.
您也可以考虑在 x-axis
上有 8 个条目
ggplot(titer_lung, aes(y=X1, x=paste(X3,X2), fill=X2)) + ...
my_comparisons <- list(c("mutIRFE_FB -NK","mutIRFE_FB NK"),
c("mutIRFErev_FB -NK","mutIRFErev_FB NK"),
c("d3IDE mutIRFE -NK","d3IDE mutIRFE NK"),
c("d3IDE mutIRFErev -NK","d3IDE mutIRFErev NK"))
titer_plot + stat_compare_means(comparisons=my_comparisons, label.y=5,
method = "t.test")
我正在用 ggplot2, which works fine. But if I am using stat_compare_means
from the ggpubr
package to add p-value 绘制一个 grouped dotplot
,它不会工作。当我在绘图环境之外使用 compare_means
时,它工作正常并且我得到了正确的 p-values
数据集(使用 compare_means(X1 ~ X5, data=titer_lung, method="t.test"
)。
我正在使用以下数据:
> titer_lung
X1 X2 X3 X4 X5
1 4.531479 NK mutIRFE_FB Lunge group1
2 4.068186 NK mutIRFE_FB Lunge group1
3 4.071882 NK mutIRFE_FB Lunge group1
4 4.117271 NK mutIRFE_FB Lunge group1
5 4.117271 NK mutIRFE_FB Lunge group1
6 4.462398 -NK mutIRFE_FB Lunge group2
7 4.643453 -NK mutIRFE_FB Lunge group2
8 4.556303 -NK mutIRFE_FB Lunge group2
9 4.724276 -NK mutIRFE_FB Lunge group2
10 4.491362 -NK mutIRFE_FB Lunge group2
11 3.903090 NK mutIRFErev_FB Lunge group3
12 4.342423 NK mutIRFErev_FB Lunge group3
13 4.113943 NK mutIRFErev_FB Lunge group3
14 4.653213 NK mutIRFErev_FB Lunge group3
15 4.230449 NK mutIRFErev_FB Lunge group3
16 4.556303 -NK mutIRFErev_FB Lunge group4
17 4.462398 -NK mutIRFErev_FB Lunge group4
18 4.230449 -NK mutIRFErev_FB Lunge group4
19 NA -NK mutIRFErev_FB Lunge group4
20 4.591065 -NK mutIRFErev_FB Lunge group4
21 4.230449 NK d3IDE mutIRFE Lunge group5
22 4.531479 NK d3IDE mutIRFE Lunge group5
23 4.812913 NK d3IDE mutIRFE Lunge group5
24 4.544068 NK d3IDE mutIRFE Lunge group5
25 4.342423 NK d3IDE mutIRFE Lunge group5
26 4.380211 -NK d3IDE mutIRFE Lunge group6
27 4.698970 -NK d3IDE mutIRFE Lunge group6
28 4.716003 -NK d3IDE mutIRFE Lunge group6
29 4.477121 -NK d3IDE mutIRFE Lunge group6
30 4.740363 -NK d3IDE mutIRFE Lunge group6
31 4.255273 NK d3IDE mutIRFErev Lunge group7
32 4.322219 NK d3IDE mutIRFErev Lunge group7
33 4.113943 NK d3IDE mutIRFErev Lunge group7
34 4.176091 NK d3IDE mutIRFErev Lunge group7
35 4.518514 NK d3IDE mutIRFErev Lunge group7
36 4.724276 -NK d3IDE mutIRFErev Lunge group8
37 4.462398 -NK d3IDE mutIRFErev Lunge group8
38 4.785330 -NK d3IDE mutIRFErev Lunge group8
39 4.431364 -NK d3IDE mutIRFErev Lunge group8
40 4.826075 -NK d3IDE mutIRFErev Lunge group8
通过使用以下代码,我得到了我正在寻找的情节:
titer_plot <- ggplot(titer_lung, aes(y=titer_lung$X1, x=titer_lung$X3,
fill=titer_lung$X2)) +
geom_dotplot(aes(fill = titer_lung$X2, color = titer_lung$X2),
trim = FALSE,
binaxis='y', stackdir='center', dotsize = 0.8,
position = position_dodge(0.8)
)+
stat_summary(fun.y = median, fun.ymin = median, fun.ymax = median,
geom = "crossbar", width = 0.5, position = position_dodge(0.8)) +
scale_fill_manual(values = c("black", "white"))+
scale_color_manual(values = c("black", "black"))+
xlab("")+
ylab(expression('Viral titer/organ [log '[10]*']'))+
theme_classic()+
theme(text = element_text(size=10),
axis.text.x = element_text(size=10, angle = 90, hjust=1),
axis.text.y = element_text(size=10),
axis.title.y = element_text(size=10), legend.text = element_text(size=10),
legend.title=element_blank())+
titer_plot
当我想比较 group1 和 group2 以及 group3 和 group4 时,我写:
my_comparisons <- list(c("group1","group2"),c("group3","group4"))
titer_plot + stat_compare_means(comparisons=my_comparisons, label.y=0,
method = "t.test")
但随后我收到以下错误:
Removed 1 rows containing non-finite values (stat_signif).
Computation failed instat_signif()
: missing value where TRUE/FALSE needed
我想 NA
值应该没有问题,因为 compare_means
也没有问题。
我很高兴得到每一个帮助,谢谢!!!
问题是,不知道括号放在哪里(x-coordinates)
comparisons: A list of length-2 vectors. The entries in the vector are either the names of 2 values on the x-axis or the 2 integers that correspond to the index of the groups of interest, to be compared.
titer_plot + stat_compare_means(aes(group=X2), method = "t.test",) #specify the groups specifically
label.y=5
我不知道如何克服这个问题,但底层 geom_signif
有一个 "manual" 论点。所以我想你可以以某种方式将 compare_means(X1 ~ X5, data=titer_lung, method="t.test")
的输出提供给这个 geom.
您也可以考虑在 x-axis
上有 8 个条目ggplot(titer_lung, aes(y=X1, x=paste(X3,X2), fill=X2)) + ...
my_comparisons <- list(c("mutIRFE_FB -NK","mutIRFE_FB NK"),
c("mutIRFErev_FB -NK","mutIRFErev_FB NK"),
c("d3IDE mutIRFE -NK","d3IDE mutIRFE NK"),
c("d3IDE mutIRFErev -NK","d3IDE mutIRFErev NK"))
titer_plot + stat_compare_means(comparisons=my_comparisons, label.y=5,
method = "t.test")