经常遇到‘一个循环绘制每一个差异基因在肿瘤和正常的表达差异’和‘需要在一张图中展示多个差异基因在肿瘤和正常组的表达分布’需求。如下列两张图所示:
然后循环作图:
list <- names(data)[2:11]
list
plot_list = list()
for (i in 1:3) {
p = ggboxplot(data, x='group', y= as.character(list[i]),
bxp.errorbar = T, color = 'group',
outlier.shape = NA, add = "point",
palette =c("#00AFBB","#FC4E07") )+stat_compare_means()
plot_list[[i]] = p }
# Another option: create pdf where each page is a separate plot.
pdf("plots.pdf")
for (i in 1:10) {print(plot_list[[i]]) }
dev.off()
#=======================================================
#一张图
#=======================================================
library(reshape2)
library(tidyr)
colnames(data)
names(data)[2]
names(data)[11]
#使用data数据框中非subtype的第一个列名和最后一个列名
data1 <- gather(data, gene, count, BCL11A:ZCCHC7 )
head(data1)
p <- ggboxplot(data1, x = "gene", y = "count",size=0.5, bxp.errorbar = T,
color = "group", palette =c( "#FC4E07", "#00AFBB"),
add.params = list(size=0.5), outlier.shape = NA,
add = "point") +
stat_compare_means(aes(group = group), label = "p.format")
p
pdf(file = 'expr_subtype.pdf', height = 4,width = 14)
p
dev.off()
扫码关注腾讯云开发者
领取腾讯云代金券
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. 腾讯云 版权所有