其他
ggplot 绘制小提琴图+箱线图+统计检验
点击上方关注老俊俊
1引言
我在知识星球分享了一个图,有小伙伴在下方留言说想要代码
,今日分享一下绘图代码:
原图:
也欢迎感兴趣的小伙伴加入进来:
2绘图
准备数据:
library(tidyverse)
library(ggpubr)
df <- read.csv('YTHDF1_mRNA_pancan_dist.csv') %>%
filter(tissue %in% c('ACC','BLCA','KICH','KIRC','PCPG','PRAD','READ','UCS'))
colnames(df)
# [1] "tpm" "tissue" "type2" "sample" "dataset"
# check
head(df)
# tpm tissue type2 sample dataset
# 1 4.804 KIRC normal TCGA-B2-5641-11 TCGA
# 2 4.333 READ normal GTEX-WQUQ-2526-SM-4MVNO GTEX
# 3 4.583 PRAD tumor TCGA-EJ-7125-01 TCGA
# 4 4.485 PRAD tumor TCGA-KK-A7B3-01 TCGA
# 5 4.783 KIRC tumor TCGA-BP-4765-01 TCGA
# 6 3.806 KIRC tumor TCGA-CZ-5459-01 TCGA
这里只挑选了 8 个癌症及其正常组织的样本来画图。
绘图:
# plot
ggplot(df,aes(x = tissue, y = log2(tpm+0.1),fill = type2)) +
# 小提琴图层
geom_violin(position = position_dodge(0.9),alpha = 0.5,
width = 1.2,trim = T,
color = NA) +
# 箱线图图层
geom_boxplot(width = .2,show.legend = F,
position = position_dodge(0.9),
color = 'grey20',alpha = 0.5,
outlier.color = 'grey50') +
# 主题调整
theme_bw(base_size = 16) +
theme(axis.text.x = element_text(angle = 45,hjust = 1,color = 'black'),
legend.position = 'top',
aspect.ratio = 0.4) +
# 颜色设置
scale_fill_manual(values = c('normal'='#398AB9','tumor'='red'),
name = '') +
# 添加显著性标记
stat_compare_means(aes(group=type2),
symnum.args=list(cutpoints = c(0, 0.001, 0.01, 0.05, 1),
symbols = c("***", "**", "*", "NS")),label = "p.signif",
label.y = 3,size = 5) +
ylim(0.5,3.5)
3结尾
小伙伴们可以自行拿数据进行尝试。
欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群
哦,数据代码已上传至QQ群,欢迎加入下载。
群二维码:
老俊俊微信:
知识星球:
所以今天你学习了吗?
今天的分享就到这里了,敬请期待下一篇!
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,赏杯快乐水喝喝吧!
往期回顾
◀跟着 Cell Reports 学做图-CLIP-seq 数据可视化
◀m6A enrichment on peak center
◀m6A metagene distribution 纠正坐标
◀m6A metagene distribution 计算详解
◀跟着 nature cell biology 学绘图-小提琴图
◀...