美文网首页
[复现NC]R语言一键画表达量箱线图并添加显著性|转载

[复现NC]R语言一键画表达量箱线图并添加显著性|转载

作者: Zukunft_Lab | 来源:发表于2022-08-05 00:50 被阅读0次

    可视化结果:

    图片.png

    数据输入

    画图数据需要两个文件,一个是表达量数据,列为样本,行为基因。另外一个是注释信息,是关于样本分组的。

    表达数据:


    图片.png

    样本信息:


    图片.png

    代码

    library(RColorBrewer)
    library(ggpubr)
    library(ggplot2)
    library(cowplot)
    
    
    setwd("D:/生物信息学")
    Exp <- read.csv("Exp.csv",header=T,row.names=1)#读入源文件
    gene <- c("CD28","CD3D","CD8A","LCK",
              "GATA3","EOMES","IL23A","CXCL8",
              "IL1R2","IL1R1","MMP8","MMP9")#这里我们只选择这几个基因做数据
    gene <- as.vector(gene)
    Exp <- log2(Exp+1) #因为是FPKM数据,标准化一下
    Exp_plot <- Exp[,gene]#提取需要作图得基因表达信息
    
    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表示图片排为几列
    
    
    图片.png

    相关文章

      网友评论

          本文标题:[复现NC]R语言一键画表达量箱线图并添加显著性|转载

          本文链接:https://www.haomeiwen.com/subject/qdymwrtx.html