❝此图归类于簇状箱线图,图中叠加元素主要有阴影背景条带、p值、显著性条带、图例文本颜色、图例位置等,细节繁多需要调整多个参数 ❞
❝给予长期支持我们的读者们一个特别待遇:购买小编VIP会员文档的读者,「将自动获得2024年及以后更新的绘图文档代码,无需额外付费」。目前会员文档(2023+2024)「已经更新上传了140+案例文档」,每个案例都附有相应的数据和代码,并配有对应的注释文档,方便大家学习和参考。 ❞
install.packages("ggplot2")
library(tidyverse)
library(rstatix)
library(GGally)
library(ggtext)
df <- read_tsv("diff_GeneExp.txt") %>%
pivot_longer(-ID) %>%
mutate(type=map_chr(name, ~str_split(.x, "_")[[1]][length(str_split(.x, "_")[[1]])]))
df_pvalue <- df %>% group_by(ID) %>%
wilcox_test(value ~type) %>%
adjust_pvalue(p.col = "p", method = "bonferroni") %>%
add_significance(p.col = "p.adj") %>%
select(ID,p.adj)
dff <- df %>% left_join(.,df_pvalue,by="ID") %>%
mutate(group=case_when(p.adj < 0.00001 ~ "Upregulated",
TRUE ~ "NS")) %>%
mutate(p.adj=paste("p=",p.adj,sep=""))
dff %>% ggplot(aes(value,ID))+
geom_stripped_rows(odd="grey90",xfrom =-0.5, xto =9.5)+
geom_boxplot(aes(color=type),position = position_dodge(0.5),
width=0.5,outliers = FALSE)+
geom_text(data=dff %>% select(1,p.adj) %>% distinct(),
aes(x=8.2,y=ID,label=p.adj),size=3,color="black")+
scale_x_continuous(limits = c(0,10),breaks = c(2,4,6,8))+
scale_y_discrete(expand =c(0,0.5))+
scale_fill_manual(values =c("Upregulated"="#7294D4","NS"="grey"))+
labs(x=NULL,y=NULL)+
theme_classic()+
theme(plot.margin=unit(c(0.5,0.5,0.5,0.5),unit="cm"),
legend.justification.top = "left",
legend.text = element_markdown(),
legend.background = element_blank(),
axis.line.x.bottom = element_blank(),
axis.text=element_text(color="black"))
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有