提问人:ElsaC 提问时间:11/16/2023 更新时间:11/16/2023 访问量:9
如何将wilcox.test pvalue添加到Facet_nested ggplot对象(例如使用geom_signif?
How to add wilcox.test pvalue to a Facet_nested ggplot object (using geom_signif for example ?)?
问:
我正在尝试构建一个 ggplot,我可以在其中添加结果。facet_nested
Wilcox.test
scenarios
我有以下数据框:
structure(list(scenario = c("DEG DB-S", "DEG DB-S", "DEG DB-S",
"DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S",
"DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S",
"DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S",
"DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG DB-S",
"DEG DB-S", "DEG DB-S", "DEG DB-S", "DEG R-S", "DEG R-S", "DEG R-S",
"DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S",
"DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S",
"DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S",
"DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S", "DEG R-S",
"DEG R-S", "DEG R-S", "DEG R-S", "Var DB-S", "Var DB-S", "Var DB-S",
"Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S",
"Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S",
"Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S",
"Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S", "Var DB-S",
"Var DB-S", "Var DB-S", "Var DB-S", "Var R-S", "Var R-S", "Var R-S",
"Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S",
"Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S",
"Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S",
"Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S", "Var R-S",
"Var R-S", "Var R-S", "Var R-S"), replicates = c("A_S10x", "A_S1x",
"A_S2x", "A_S3x", "A_S4x", "A_S5x", "A_S6x", "A_S7x", "A_S8x",
"A_S9x", "B_S10x", "B_S1x", "B_S2x", "B_S3x", "B_S4x", "B_S5x",
"B_S6x", "B_S7x", "B_S8x", "B_S9x", "C_S10x", "C_S1x", "C_S2x",
"C_S3x", "C_S4x", "C_S5x", "C_S6x", "C_S7x", "C_S8x", "C_S9x",
"A_S10x", "A_S1x", "A_S2x", "A_S3x", "A_S4x", "A_S5x", "A_S6x",
"A_S7x", "A_S8x", "A_S9x", "B_S10x", "B_S1x", "B_S2x", "B_S3x",
"B_S4x", "B_S5x", "B_S6x", "B_S7x", "B_S8x", "B_S9x", "C_S10x",
"C_S1x", "C_S2x", "C_S3x", "C_S4x", "C_S5x", "C_S6x", "C_S7x",
"C_S8x", "C_S9x", "A_S10x", "A_S1x", "A_S2x", "A_S3x", "A_S4x",
"A_S5x", "A_S6x", "A_S7x", "A_S8x", "A_S9x", "B_S10x", "B_S1x",
"B_S2x", "B_S3x", "B_S4x", "B_S5x", "B_S6x", "B_S7x", "B_S8x",
"B_S9x", "C_S10x", "C_S1x", "C_S2x", "C_S3x", "C_S4x", "C_S5x",
"C_S6x", "C_S7x", "C_S8x", "C_S9x", "A_S10x", "A_S1x", "A_S2x",
"A_S3x", "A_S4x", "A_S5x", "A_S6x", "A_S7x", "A_S8x", "A_S9x",
"B_S10x", "B_S1x", "B_S2x", "B_S3x", "B_S4x", "B_S5x", "B_S6x",
"B_S7x", "B_S8x", "B_S9x", "C_S10x", "C_S1x", "C_S2x", "C_S3x",
"C_S4x", "C_S5x", "C_S6x", "C_S7x", "C_S8x", "C_S9x"), subspecies = c("A",
"A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C",
"C", "C", "C", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "C", "C", "C",
"C", "C", "C", "C", "C", "C", "C", "A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "C", "C", "C", "C", "C", "C", "C", "C", "C", "C", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "C",
"C", "C"), species_name = c("Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_1", "Species_1", "Species_1",
"Species_1", "Species_1", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2", "Species_2", "Species_2", "Species_2",
"Species_2", "Species_2"), condition = c("DEG DB-S_A", "DEG DB-S_A",
"DEG DB-S_A", "DEG DB-S_A", "DEG DB-S_A", "DEG DB-S_A", "DEG DB-S_A",
"DEG DB-S_A", "DEG DB-S_A", "DEG DB-S_A", "DEG DB-S_B", "DEG DB-S_B",
"DEG DB-S_B", "DEG DB-S_B", "DEG DB-S_B", "DEG DB-S_B", "DEG DB-S_B",
"DEG DB-S_B", "DEG DB-S_B", "DEG DB-S_B", "DEG DB-S_C", "DEG DB-S_C",
"DEG DB-S_C", "DEG DB-S_C", "DEG DB-S_C", "DEG DB-S_C", "DEG DB-S_C",
"DEG DB-S_C", "DEG DB-S_C", "DEG DB-S_C", "DEG R-S_A", "DEG R-S_A",
"DEG R-S_A", "DEG R-S_A", "DEG R-S_A", "DEG R-S_A", "DEG R-S_A",
"DEG R-S_A", "DEG R-S_A", "DEG R-S_A", "DEG R-S_B", "DEG R-S_B",
"DEG R-S_B", "DEG R-S_B", "DEG R-S_B", "DEG R-S_B", "DEG R-S_B",
"DEG R-S_B", "DEG R-S_B", "DEG R-S_B", "DEG R-S_C", "DEG R-S_C",
"DEG R-S_C", "DEG R-S_C", "DEG R-S_C", "DEG R-S_C", "DEG R-S_C",
"DEG R-S_C", "DEG R-S_C", "DEG R-S_C", "Var DB-S_A", "Var DB-S_A",
"Var DB-S_A", "Var DB-S_A", "Var DB-S_A", "Var DB-S_A", "Var DB-S_A",
"Var DB-S_A", "Var DB-S_A", "Var DB-S_A", "Var DB-S_B", "Var DB-S_B",
"Var DB-S_B", "Var DB-S_B", "Var DB-S_B", "Var DB-S_B", "Var DB-S_B",
"Var DB-S_B", "Var DB-S_B", "Var DB-S_B", "Var DB-S_C", "Var DB-S_C",
"Var DB-S_C", "Var DB-S_C", "Var DB-S_C", "Var DB-S_C", "Var DB-S_C",
"Var DB-S_C", "Var DB-S_C", "Var DB-S_C", "Var R-S_A", "Var R-S_A",
"Var R-S_A", "Var R-S_A", "Var R-S_A", "Var R-S_A", "Var R-S_A",
"Var R-S_A", "Var R-S_A", "Var R-S_A", "Var R-S_B", "Var R-S_B",
"Var R-S_B", "Var R-S_B", "Var R-S_B", "Var R-S_B", "Var R-S_B",
"Var R-S_B", "Var R-S_B", "Var R-S_B", "Var R-S_C", "Var R-S_C",
"Var R-S_C", "Var R-S_C", "Var R-S_C", "Var R-S_C", "Var R-S_C",
"Var R-S_C", "Var R-S_C", "Var R-S_C"), value = c(0.98172, 0.978652916666667,
0.99991, 0.97994, 0.993644583333333, 0.95744375, 0.980380833333333,
0.998727083333333, 0.984138333333333, 0.995765, 0.988333333333333,
0.992666666666667, 1, 0.984333333333333, 0.99, 0.960333333333333,
0.991666666666667, 0.984, 0.994, 0.990666666666667, 0.665374727668845,
0.662200873362445, 0.664629955947137, 0.65590989010989, 0.667090507726269,
0.663162790697674, 0.67621412803532, 0.657115044247788, 0.667743929359823,
0.670337004405286, 0.992484583333333, 0.99117625, 0.997137916666667,
0.971002083333333, 0.992359166666667, 0.984022916666667, 0.976832083333333,
0.99386, 0.990916666666667, 0.99885625, 1, 1, 0.996666666666667,
0.989666666666667, 0.998666666666667, 0.994666666666667, 0.991666666666667,
0.998, 0.999333333333333, 1, 0.659840611353712, 0.673435164835165,
0.663804772234273, 0.661091703056769, 0.652524017467249, 0.667353846153846,
0.664973509933775, 0.660403050108932, 0.666209713024283, 0.667819383259912,
0.865045416666667, 0.834530833333333, 0.826324583333333, 0.837911666666667,
0.805854166666667, 0.83401875, 0.79532875, 0.830845416666667,
0.830444583333333, 0.866255, 0.856666666666667, 0.837, 0.832,
0.840333333333333, 0.793, 0.832666666666667, 0.802, 0.849666666666667,
0.859333333333333, 0.877666666666667, 0.533706018518519, 0.491011764705882,
0.496581395348837, 0.513160465116279, 0.496923627684964, 0.50288056206089,
0.485009367681499, 0.501932084309133, 0.501605568445476, 0.516875,
0.828203333333333, 0.831938333333333, 0.83821875, 0.838965833333333,
0.8511625, 0.8356775, 0.820040416666667, 0.83255625, 0.8550125,
0.830418333333333, 0.853333333333333, 0.845, 0.864666666666667,
0.850333333333333, 0.858, 0.828666666666667, 0.831, 0.854333333333333,
0.856666666666667, 0.857666666666667, 0.518638051044084, 0.504856812933025,
0.472275294117647, 0.498741258741259, 0.49295337995338, 0.480641330166271,
0.494142523364486, 0.486962877030162, 0.518133640552995, 0.501102870813397
)), row.names = c(NA, -120L), class = "data.frame")
这是我的原始数据帧的子集。
现在,在这篇文章的后面,我设法得到了这个情节:
为此,我使用了以下代码:
ggplot(copy2, aes(x=scenario, y=value, color=subspecies)) +
geom_boxplot(lwd = 0.4, fatten = 1)+
facet_nested(.~species_name+subspecies,
labeller = label_wrap_gen(5),
strip = strip_nested(size = "variable"),
scales = "free",
space='free')+
scale_y_continuous(breaks=seq(0,1,by=0.1),limits = c(0, 1.1))+
theme(axis.text.x = element_text(angle=70,hjust=1,vjust=1,face="plain"))+
geom_signif(test='wilcox.test', comparisons = combn(levels(copy$scenario),2,simplify = F),
map_signif_level = T)
我不明白为什么我只有 6 个(我认为?)比较(为什么尤其是这些?),而我应该有更多。
理想情况下,在绘图的每个面板(例如:面板Species_1 -> A)中,我想获得 4 对比较的结果,例如:facet_nested
wilcox.test
DEG DB-S vs DEG R-S
Var DB-S vs Var R-S
DEG DB-S vs Var DB-S
DEG R-S vs Var R-S
这些是我的变量中包含的值。scenario
我知道在我的数据框中,我应该拥有所有变量来做我想做的事,但我不知道如何使用它们。
我更愿意使用它来实现它,但当然,我对所有可以帮助我的解决方案都持开放态度。geom_signif
提前非常感谢您抽出时间接受采访,
艾 尔 莎
答: 暂无答案
评论