如何自动增加最高值和显着性条之间的space & 中间有显着性标签?
How to automatically increase the space between the highest value and significance bar & have significance label in the middle?
我有如下图表:
我的数据是这样的:
structure(list(Time = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("30 (min)", "60 (min)",
"90 (min)"), class = "factor"), CC = c(48L, 48L, 48L, 48L, 48L,
48L, 48L, 48L, 48L, 48L, 48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L,
48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 48L, 48L, 48L, 48L, 48L,
48L, 48L, 48L, 48L, 48L, 48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), logSG = c(-2.33741545784603, -1.18658485472471, 0, 0,
-0.491782643217124, 3.69448372083377, 4.5407591512423, 2.61268192437219,
3.86060133588356, 0, 0, 0, 0, -1.96969067772072, 1.14869526758596,
0, 0, 0.415146522977509, -0.493822991230427, 4.41801522125664,
0.77745996724697, 0, 3.45614515898878, 5.0294054937422, 4.11407093388758,
5.89718763629734, 0, 5.33908355911139, 5.07344324140438, 6.31055955347468,
6.26791733683611, 6.25584328404724, 5.07460803880627, -1.14240744866778,
6.77709746094989, 5.83911536618483, 2.67579059651909, -0.0581215539811307,
7.58033720832469, 6.76794295683794, 6.93585146776912, 5.73947045554567,
0, 6.14529708204681, 5.36852954870684, 6.37769853018143, 6.69908148274872,
6.85439184110933, 5.92974818275192, 8.00503455012466, 6.90732500418721,
7.72752338652543, 3.69803617369367, 3.94835058665366, 0.196314345332914,
5.14495801055901, 7.13859356791309, 8.10996479358517, 5.69942374886411,
6.97130919360524, 7.76540068911542, 7.40190399204928)), row.names = c(NA,
-62L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7faf890130e0>)
我的代码如下所示:
p <- ggboxplot(test, x="CC", y="logSG", color ="CC", palette=c("#E69F00", "#56B4E9"), alpha=.9, add="jitter", shape="CC", facet.by="Time", short.panel.labs=F, outlier.shape = NA, rotate=T)
p <- p + stat_compare_means(comparisons= list(c("48", "0")), label="p.signif", size=8)
facet(p, facet.by="Time", ncol=1)+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
我愿意:
- 显着性条更靠左(在条与 90(分钟)条件下的最高值之间有更多 space。
- 在显着性条的右侧和中间有显着性标签 (ns, *, **)
- 更改抖动颜色以匹配填充颜色(但箱线图仍然保持黑色边框)
感谢您的帮助。
当前进度:
全部数据:
structure(list(Time = c("30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)"), CC = c("48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"
), logSG = c(-2.33741545784603, -1.5359551356743, -0.706559805935718,
0.708497262914779, -1.18658485472471, 0, 0.215424357929406, 0,
0, -0.669164283172473, -1.05979396415459, -2.31882739909547,
0, 0.42055843809296, 0.0345207061138516, 0.490214669861868, -0.491782643217124,
-0.40943698558059, 5.29576170328759, 3.00786490791837, 3.69448372083377,
0, 1.13692090507591, 3.90397709096783, 4.5407591512423, 0.959448191357494,
0.812996456139986, 0.387663144815093, 2.61268192437219, 5.70801342338959,
0, 4.06129455674501, 3.86060133588356, 2.96113466195081, 4.31811283391345,
6.02174904012545, 0, 0, 3.63890951803723, 4.15432961681392, 0,
5.62437201872284, 0, -0.172668794962532, 0, 0.885684238138353,
0.458386726057045, 0.93033451187609, 0, -0.916540763129364, 0.672683864147678,
0, -1.96969067772072, -0.211359094917249, 0, 0, 1.14869526758596,
0.855485393729508, 1.51470800852286, 1.25969589114081, 0, 5.55360595405316,
0, 0, 0, 0.608132989683934, 0.766711429029875, 0.0230319883972058,
0.415146522977509, 0.989351045425203, 0.764590061654141, 0, -0.493822991230427,
-3.04352293739034, 0.113154350383661, 0.477535633527187, 4.41801522125664,
0, 0.790376357072563, 5.33363551675867, 0.77745996724697, -1.39120640548091,
2.81038881541196, 0.909530012962848, 0, 0, 0, -1.32462975739634,
3.45614515898878, 2.87635990847717, 6.14131074674228, 4.94317084553412,
5.0294054937422, 3.6735726222342, 0, 0, 4.11407093388758, 0,
0, 0, 5.89718763629734, 0, -2.83568067112007, -1.08417160451332,
0, 0, 0, -1.79669470441478, 5.33908355911139, 4.34702414757653,
4.97832646498993, 5.68601129052879, 5.07344324140438, 7.32969721447871,
5.88124362908576, 3.95375517761101, 6.31055955347468, 6.68105022814714,
0, 0, 6.26791733683611, 6.6552388904731, 6.1554345645557, 6.16783228738057,
6.25584328404724, 7.40421295863169, 4.42098910134338, 4.34381971828829,
5.07460803880627, 4.05138376423435, 5.66021948971494, 6.4161744214807,
-1.14240744866778, -1.59148885378724, 4.96717393543566, 4.05185180788696,
6.77709746094989, 7.33240191526984, 4.40167592777489, 5.00079217967616,
5.83911536618483, 4.87041813930411, 5.4798591602912, 5.8840457498263,
2.67579059651909, 0, 4.55901232476737, -1.60364223983752, -0.0581215539811307,
2.82972718294857, 6.25577118949695, 6.72479834475368, 7.58033720832469,
6.73711432644271, 6.00469556652024, 4.37286341669336, 6.76794295683794,
6.95437999496909, 5.54915990369101, 7.19992007355504, 6.93585146776912,
6.31917969823023, 6.88303863646214, 5.80298414483425, 5.73947045554567,
5.42427157341921, 6.02067813111897, 7.06513961445597, 0, 5.14873092690417,
4.99432854142356, 4.97613488925218, 6.14529708204681, 0.241208512880646,
5.61581002162685, -0.428836094431404, 5.36852954870684, 6.969161017026,
6.4311112305739, -0.488846717047216, 6.37769853018143, 6.06472694568864,
5.91882885723854, 6.75183187908138, 6.69908148274872, 6.09707860117223,
7.51181134639969, 7.70390188945798, 6.85439184110933, 7.06474253499617,
6.06324707449019, 7.01225437796713, 5.92974818275192, 4.38046495874971,
4.93237626658016, 6.42814116590149, 8.00503455012466, 6.52016300282035,
5.631222408333, 6.00091375144581, 6.90732500418721, 7.06335795773428,
6.5320791891557, 7.61232026906213, 7.72752338652543, 6.5686929033117,
2.95760357016318, 0.536708150079365, 3.69803617369367, -0.762215947784048,
0.813262309586256, 0.09473936757137, 3.94835058665366, 4.8306952746183,
6.08818108540523, -2.28999797748857, 0.196314345332914, 4.89645977132752,
4.92651109236787, 0, 5.14495801055901, 5.61854564628758, 4.6634157508477,
5.61755666066751, 7.13859356791309, 7.53514925442216, 8.07256779525966,
8.35325245369136, 8.10996479358517, 7.4087861988897, 7.39596849037868,
7.59049483086555, 5.69942374886411, 6.51587453730492, 6.3129579179017,
7.5183813575123, 6.97130919360524, 7.76889903023342, 7.95470129243914,
7.2816428879755, 7.76540068911542, 7.66318176453257, 6.74009737270994,
6.68085256625662, 7.40190399204928, 8.60372201882463, 6.62079617953904,
8.22461607745356)), row.names = c(NA, -248L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7faf890130e0>)
当前代码:
ggplot(result, aes(x = as.factor(CC), y = logSG, color = as.factor(CC),
shape = as.factor(CC),
fill = as.factor(CC)))+
geom_boxplot(color = "black", alpha = 0.2, outlier.shape = NA)+
geom_jitter(width = 0.2)+
geom_signif(comparisons = list(c("48","0")),
y_position = max(result$logSG, na.rm = TRUE)+1, hjust = -.75, vjust = 1.5, color = "black", show.legend = FALSE,
textsize = 8, map_signif_level=TRUE)+
scale_color_manual(values = c("#E69F00", "#56B4E9"))+
scale_fill_manual(values = c("#E69F00", "#56B4E9"))+
facet_wrap(Time~., ncol = 1)+
ylim(min(result$logSG, na.rm = TRUE)-.25, max(result$logSG, na.rm = TRUE)+3.5)+
coord_flip()+
labs(color = "CC",fill = "CC", shape = "CC", x = "CC")+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
我认为 coord_flip
对 hjust
和 vjust
做了一些时髦的事情。无论如何要操纵这个?没有的话我就用illustrator什么的
使用 stat_compare_means
,我没有找到一种方法来获得你想要的调整标签位置的重要性(我认为分面与 label.y
参数的使用混淆) ,所以我使用了 ggsignif
包中的 geom_signif
函数,我玩了一点 hjust
、vjust
和 y_position
。
我还使用 ggplot
而不是 ggboxplot
来绘制箱线图,因为这样您可以分别操作箱线图和抖动点的颜色和填充。
此处,我根据您的示例使用的代码:
library(ggplot2)
library(ggsignif)
ggplot(df, aes(x = as.factor(CC), y = logSG, color = as.factor(CC),
shape = as.factor(CC),
fill = as.factor(CC)))+
geom_boxplot(color = "black", alpha = 0.2)+
geom_jitter(width = 0.2)+
geom_signif(comparisons = list(c("48","0")),
y_position = 9, hjust = -0.75, vjust = 1.5, color = "black", show.legend = FALSE,
textsize = 8, map_signif_level=TRUE)+
scale_color_manual(values = c("#E69F00", "#56B4E9"))+
scale_fill_manual(values = c("#E69F00", "#56B4E9"))+
facet_wrap(Time~., ncol = 1)+
ylim(-3,10)+
coord_flip()+
labs(color = "CC",fill = "CC", shape = "CC", x = "CC")+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
它看起来像你想要达到的目标吗?
我有如下图表:
我的数据是这样的:
structure(list(Time = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("30 (min)", "60 (min)",
"90 (min)"), class = "factor"), CC = c(48L, 48L, 48L, 48L, 48L,
48L, 48L, 48L, 48L, 48L, 48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L,
48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 48L, 48L, 48L, 48L, 48L,
48L, 48L, 48L, 48L, 48L, 48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L), logSG = c(-2.33741545784603, -1.18658485472471, 0, 0,
-0.491782643217124, 3.69448372083377, 4.5407591512423, 2.61268192437219,
3.86060133588356, 0, 0, 0, 0, -1.96969067772072, 1.14869526758596,
0, 0, 0.415146522977509, -0.493822991230427, 4.41801522125664,
0.77745996724697, 0, 3.45614515898878, 5.0294054937422, 4.11407093388758,
5.89718763629734, 0, 5.33908355911139, 5.07344324140438, 6.31055955347468,
6.26791733683611, 6.25584328404724, 5.07460803880627, -1.14240744866778,
6.77709746094989, 5.83911536618483, 2.67579059651909, -0.0581215539811307,
7.58033720832469, 6.76794295683794, 6.93585146776912, 5.73947045554567,
0, 6.14529708204681, 5.36852954870684, 6.37769853018143, 6.69908148274872,
6.85439184110933, 5.92974818275192, 8.00503455012466, 6.90732500418721,
7.72752338652543, 3.69803617369367, 3.94835058665366, 0.196314345332914,
5.14495801055901, 7.13859356791309, 8.10996479358517, 5.69942374886411,
6.97130919360524, 7.76540068911542, 7.40190399204928)), row.names = c(NA,
-62L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7faf890130e0>)
我的代码如下所示:
p <- ggboxplot(test, x="CC", y="logSG", color ="CC", palette=c("#E69F00", "#56B4E9"), alpha=.9, add="jitter", shape="CC", facet.by="Time", short.panel.labs=F, outlier.shape = NA, rotate=T)
p <- p + stat_compare_means(comparisons= list(c("48", "0")), label="p.signif", size=8)
facet(p, facet.by="Time", ncol=1)+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
我愿意:
- 显着性条更靠左(在条与 90(分钟)条件下的最高值之间有更多 space。
- 在显着性条的右侧和中间有显着性标签 (ns, *, **)
- 更改抖动颜色以匹配填充颜色(但箱线图仍然保持黑色边框)
感谢您的帮助。
当前进度:
全部数据:
structure(list(Time = c("30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)", "30 (min)",
"30 (min)", "30 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)", "60 (min)",
"60 (min)", "60 (min)", "60 (min)", "60 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)", "90 (min)",
"90 (min)", "90 (min)", "90 (min)", "90 (min)"), CC = c("48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "48", "48", "48",
"48", "48", "48", "48", "48", "48", "48", "48", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"
), logSG = c(-2.33741545784603, -1.5359551356743, -0.706559805935718,
0.708497262914779, -1.18658485472471, 0, 0.215424357929406, 0,
0, -0.669164283172473, -1.05979396415459, -2.31882739909547,
0, 0.42055843809296, 0.0345207061138516, 0.490214669861868, -0.491782643217124,
-0.40943698558059, 5.29576170328759, 3.00786490791837, 3.69448372083377,
0, 1.13692090507591, 3.90397709096783, 4.5407591512423, 0.959448191357494,
0.812996456139986, 0.387663144815093, 2.61268192437219, 5.70801342338959,
0, 4.06129455674501, 3.86060133588356, 2.96113466195081, 4.31811283391345,
6.02174904012545, 0, 0, 3.63890951803723, 4.15432961681392, 0,
5.62437201872284, 0, -0.172668794962532, 0, 0.885684238138353,
0.458386726057045, 0.93033451187609, 0, -0.916540763129364, 0.672683864147678,
0, -1.96969067772072, -0.211359094917249, 0, 0, 1.14869526758596,
0.855485393729508, 1.51470800852286, 1.25969589114081, 0, 5.55360595405316,
0, 0, 0, 0.608132989683934, 0.766711429029875, 0.0230319883972058,
0.415146522977509, 0.989351045425203, 0.764590061654141, 0, -0.493822991230427,
-3.04352293739034, 0.113154350383661, 0.477535633527187, 4.41801522125664,
0, 0.790376357072563, 5.33363551675867, 0.77745996724697, -1.39120640548091,
2.81038881541196, 0.909530012962848, 0, 0, 0, -1.32462975739634,
3.45614515898878, 2.87635990847717, 6.14131074674228, 4.94317084553412,
5.0294054937422, 3.6735726222342, 0, 0, 4.11407093388758, 0,
0, 0, 5.89718763629734, 0, -2.83568067112007, -1.08417160451332,
0, 0, 0, -1.79669470441478, 5.33908355911139, 4.34702414757653,
4.97832646498993, 5.68601129052879, 5.07344324140438, 7.32969721447871,
5.88124362908576, 3.95375517761101, 6.31055955347468, 6.68105022814714,
0, 0, 6.26791733683611, 6.6552388904731, 6.1554345645557, 6.16783228738057,
6.25584328404724, 7.40421295863169, 4.42098910134338, 4.34381971828829,
5.07460803880627, 4.05138376423435, 5.66021948971494, 6.4161744214807,
-1.14240744866778, -1.59148885378724, 4.96717393543566, 4.05185180788696,
6.77709746094989, 7.33240191526984, 4.40167592777489, 5.00079217967616,
5.83911536618483, 4.87041813930411, 5.4798591602912, 5.8840457498263,
2.67579059651909, 0, 4.55901232476737, -1.60364223983752, -0.0581215539811307,
2.82972718294857, 6.25577118949695, 6.72479834475368, 7.58033720832469,
6.73711432644271, 6.00469556652024, 4.37286341669336, 6.76794295683794,
6.95437999496909, 5.54915990369101, 7.19992007355504, 6.93585146776912,
6.31917969823023, 6.88303863646214, 5.80298414483425, 5.73947045554567,
5.42427157341921, 6.02067813111897, 7.06513961445597, 0, 5.14873092690417,
4.99432854142356, 4.97613488925218, 6.14529708204681, 0.241208512880646,
5.61581002162685, -0.428836094431404, 5.36852954870684, 6.969161017026,
6.4311112305739, -0.488846717047216, 6.37769853018143, 6.06472694568864,
5.91882885723854, 6.75183187908138, 6.69908148274872, 6.09707860117223,
7.51181134639969, 7.70390188945798, 6.85439184110933, 7.06474253499617,
6.06324707449019, 7.01225437796713, 5.92974818275192, 4.38046495874971,
4.93237626658016, 6.42814116590149, 8.00503455012466, 6.52016300282035,
5.631222408333, 6.00091375144581, 6.90732500418721, 7.06335795773428,
6.5320791891557, 7.61232026906213, 7.72752338652543, 6.5686929033117,
2.95760357016318, 0.536708150079365, 3.69803617369367, -0.762215947784048,
0.813262309586256, 0.09473936757137, 3.94835058665366, 4.8306952746183,
6.08818108540523, -2.28999797748857, 0.196314345332914, 4.89645977132752,
4.92651109236787, 0, 5.14495801055901, 5.61854564628758, 4.6634157508477,
5.61755666066751, 7.13859356791309, 7.53514925442216, 8.07256779525966,
8.35325245369136, 8.10996479358517, 7.4087861988897, 7.39596849037868,
7.59049483086555, 5.69942374886411, 6.51587453730492, 6.3129579179017,
7.5183813575123, 6.97130919360524, 7.76889903023342, 7.95470129243914,
7.2816428879755, 7.76540068911542, 7.66318176453257, 6.74009737270994,
6.68085256625662, 7.40190399204928, 8.60372201882463, 6.62079617953904,
8.22461607745356)), row.names = c(NA, -248L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x7faf890130e0>)
当前代码:
ggplot(result, aes(x = as.factor(CC), y = logSG, color = as.factor(CC),
shape = as.factor(CC),
fill = as.factor(CC)))+
geom_boxplot(color = "black", alpha = 0.2, outlier.shape = NA)+
geom_jitter(width = 0.2)+
geom_signif(comparisons = list(c("48","0")),
y_position = max(result$logSG, na.rm = TRUE)+1, hjust = -.75, vjust = 1.5, color = "black", show.legend = FALSE,
textsize = 8, map_signif_level=TRUE)+
scale_color_manual(values = c("#E69F00", "#56B4E9"))+
scale_fill_manual(values = c("#E69F00", "#56B4E9"))+
facet_wrap(Time~., ncol = 1)+
ylim(min(result$logSG, na.rm = TRUE)-.25, max(result$logSG, na.rm = TRUE)+3.5)+
coord_flip()+
labs(color = "CC",fill = "CC", shape = "CC", x = "CC")+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
我认为 coord_flip
对 hjust
和 vjust
做了一些时髦的事情。无论如何要操纵这个?没有的话我就用illustrator什么的
使用 stat_compare_means
,我没有找到一种方法来获得你想要的调整标签位置的重要性(我认为分面与 label.y
参数的使用混淆) ,所以我使用了 ggsignif
包中的 geom_signif
函数,我玩了一点 hjust
、vjust
和 y_position
。
我还使用 ggplot
而不是 ggboxplot
来绘制箱线图,因为这样您可以分别操作箱线图和抖动点的颜色和填充。
此处,我根据您的示例使用的代码:
library(ggplot2)
library(ggsignif)
ggplot(df, aes(x = as.factor(CC), y = logSG, color = as.factor(CC),
shape = as.factor(CC),
fill = as.factor(CC)))+
geom_boxplot(color = "black", alpha = 0.2)+
geom_jitter(width = 0.2)+
geom_signif(comparisons = list(c("48","0")),
y_position = 9, hjust = -0.75, vjust = 1.5, color = "black", show.legend = FALSE,
textsize = 8, map_signif_level=TRUE)+
scale_color_manual(values = c("#E69F00", "#56B4E9"))+
scale_fill_manual(values = c("#E69F00", "#56B4E9"))+
facet_wrap(Time~., ncol = 1)+
ylim(-3,10)+
coord_flip()+
labs(color = "CC",fill = "CC", shape = "CC", x = "CC")+
theme_classic(base_size = 23)+
theme(
legend.position = "top",
panel.grid.major = element_line(),
panel.grid.minor.x = element_line(color="gray", size=0.1))
它看起来像你想要达到的目标吗?