❝最近有朋友询问一张论文图的绘制方法,其本质为箱线图与棒棒糖图的结合并结合了统计分析,下面小编就通过一个案例来进行展示结果仅供参考,希望各位观众老爷能够喜欢。 ❞
❝上方的棒棒糖图为对基因内两组之间进行相关性分析的结果展示 ❞
library(tidyverse)
library(ggprism)
library(rstatix)
library(ggpubr)
library(magrittr)
library(MetBrewer)
library(patchwork)
df <- read_tsv("data.xls") %>% select(1:10,cluster) %>%
select(-ID) %>%
pivot_longer(-cluster)
df$name <- factor(df$name,levels = df$name %>% unique())
df_p_val1 <- df %>% group_by(name) %>%
wilcox_test(value ~ cluster) %>%
adjust_pvalue(p.col = "p", method = "bonferroni") %>%
add_significance(p.col = "p.adj") %>%
add_xy_position(x = "name", dodge = 0.8)
p1 <- df %>% ggplot(aes(name,value))+
stat_boxplot(geom="errorbar",aes(fill=cluster),
position=position_dodge(width=0.6),width=0.1)+
geom_boxplot(aes(fill=cluster),position=position_dodge(width =0.6),width=0.4)+
stat_pvalue_manual(df_p_val1,label = "p.adj.signif",label.size=4,hide.ns = T,
tip.length = 0.01)+
scale_size_continuous(range=c(1,3))+
scale_fill_manual(values=c("#3CB2EC","#9C8D58"))+
labs(x=NULL,y=NULL)+
theme_test()+
theme(plot.margin=unit(c(0,0.5,0.5,0.5),units=,"cm"),
axis.line = element_line(color = "black",size = 0.3),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(size = 0.2,color = "#e5e5e5"),
axis.text.y = element_text(color="black",size=8),
axis.text.x = element_text(margin = margin(t = 2),color="black",size=8),
legend.position = "none")+
coord_cartesian()