可視化結(jié)果:
數(shù)據(jù)輸入
畫圖數(shù)據(jù)需要兩個(gè)文件巡扇,一個(gè)是表達(dá)量數(shù)據(jù)摊崭,列為樣本坪圾,行為基因晓折。另外一個(gè)是注釋信息惑朦,是關(guān)于樣本分組的。
表達(dá)數(shù)據(jù):
樣本信息:
代碼
library(RColorBrewer)
library(ggpubr)
library(ggplot2)
library(cowplot)
setwd("D:/生物信息學(xué)")
Exp <- read.csv("Exp.csv",header=T,row.names=1)#讀入源文件
gene <- c("CD28","CD3D","CD8A","LCK",
"GATA3","EOMES","IL23A","CXCL8",
"IL1R2","IL1R1","MMP8","MMP9")#這里我們只選擇這幾個(gè)基因做數(shù)據(jù)
gene <- as.vector(gene)
Exp <- log2(Exp+1) #因?yàn)槭荈PKM數(shù)據(jù)漓概,標(biāo)準(zhǔn)化一下
Exp_plot <- Exp[,gene]#提取需要作圖得基因表達(dá)信息
info <- read.csv("info.csv",header=T)
Exp_plot<- Exp_plot[info$Sample,]
Exp_plot$sam=info$Type
Exp_plot$sam <- factor(Exp_plot$sam,levels=c("Asymptomatic","Mild","Severe","Critical"))
col <-c("#5CB85C","#337AB7","#F0AD4E","#D9534F")
plist2<-list()
for (i in 1:length(gene)){
bar_tmp<-Exp_plot[,c(gene[i],"sam")]
colnames(bar_tmp)<-c("Expression","sam")
my_comparisons1 <- list(c("Asymptomatic", "Mild"))
my_comparisons2 <- list(c("Asymptomatic", "Severe"))
my_comparisons3 <- list(c("Asymptomatic", "Critical"))
my_comparisons4 <- list(c("Mild", "Severe"))
my_comparisons5 <- list(c("Mild", "Critical"))
my_comparisons6 <- list(c("Severe", "Critical"))
pb1<-ggboxplot(bar_tmp,
x="sam",
y="Expression",
color="sam",
fill=NULL,
add = "jitter",
bxp.errorbar.width = 0.6,
width = 0.4,
size=0.01,
font.label = list(size=30),
palette = col)+theme(panel.background =element_blank())
pb1<-pb1+theme(axis.line=element_line(colour="black"))+theme(axis.title.x = element_blank())
pb1<-pb1+theme(axis.title.y = element_blank())+theme(axis.text.x = element_text(size = 15,angle = 45,vjust = 1,hjust = 1))
pb1<-pb1+theme(axis.text.y = element_text(size = 15))+ggtitle(gene[i])+theme(plot.title = element_text(hjust = 0.5,size=15,face="bold"))
pb1<-pb1+theme(legend.position = "NA")#
pb1<-pb1+stat_compare_means(method="t.test",hide.ns = F,
comparisons =c(my_comparisons1,my_comparisons2,my_comparisons3,my_comparisons4,my_comparisons5,my_comparisons6),
label="p.signif")
plist2[[i]]<-pb1
}
plot_grid(plist2[[1]],plist2[[2]],plist2[[3]],
plist2[[4]],plist2[[5]],plist2[[6]],
plist2[[7]],plist2[[8]],plist2[[9]],
plist2[[10]],plist2[[11]],plist2[[12]],ncol=4)#ncol=4表示圖片排為幾列