美文网首页生信绘图
个性化调整GSEAplot--第二篇

个性化调整GSEAplot--第二篇

作者: 一只烟酒僧 | 来源:发表于2022-01-27 19:14 被阅读0次
    #获得gsea对象
    gsea_obj%>%gseaplot2(.,pathway,subplots = 1) ->a
    
    #个性化调整
    a%>%.$data%>%
      mutate(gene=mapIds(org.Mm.eg.db,names(fig4_sub[[4]]@geneList),"SYMBOL","ENTREZID"))%>% #filter(position==1)
      mutate(label=ifelse(gene%in%c("Fos","Akt1","Mapk3","Ctss","Ctsd"),gene,""))%>%{
      ggplot(.)+
      geom_line(data = .,aes(x=x,y=runningScore))+
      geom_point(data = subset(.,position==1),aes(x=x,y=runningScore),color=rgb(253,174,97,max=255))+
      geom_text_repel(data = subset(.,position==1),aes(x=x,y=runningScore,label=label),color="#F39B7F",max.overlaps = 30)+
      geom_rect(data = subset(.,position==1),
                aes(xmin=x-0.001,
                    xmax=x+0.001,
                    ymin=min(runningScore)-0.25,
                    ymax=min(runningScore)-0.125,
                    color=x),
                show.legend = F)+
      geom_rect(data = .,
                aes(xmin=x-0.001,
                    xmax=x+0.001,
                    ymin=min(runningScore)-0.375,
                    ymax=min(runningScore)-0.25,
                    color=x
                    ),
                show.legend = F)+
        geom_hline(data = .,aes(yintercept = min(runningScore)-0.12),size=0.5)+
        geom_hline(yintercept = 0,lty=2,color="grey",size=1)+
        geom_vline(xintercept = median(.$x),lty=2,color="grey",size=0.5)+
        geom_segment(data = .,aes(x=max(x)*(1/4),
                                  xend=max(x)*(1/4)-max(.$x)*(1/16),
                                  y=max(runningScore)+0.1,
                                  yend=max(runningScore)+0.1), 
                     size = 2,,color=rgb(116,173,209,max=255),
                     arrow = arrow(length = unit(0.5, "cm")))+
        geom_segment(data = .,aes(x=max(x)*(3/4),
                                  xend=max(x)*(3/4)+max(.$x)*(1/16),
                                  y=max(runningScore)+0.1,
                                  yend=max(runningScore)+0.1),
                     size = 2,,color=rgb(253,174,97,max=255),
                     arrow = arrow(length = unit(0.5, "cm")))+
        annotate("text",x=max(.$x)*(3/8),y=max(.$runningScore)+0.1,label="group1",hjust=0,vjust=-0,size=5,color=rgb(116,173,209,max=255))+
        annotate("text",x=max(.$x)*(5/8),y=max(.$runningScore)+0.1,label="group2",hjust=1,vjust=-0,size=5,color=rgb(253,174,97,max=255))+
        annotate("text",x=max(.$x)*(3/4),y=0+0.05,label="runningScore=0")+
        annotate("text",x=max(.$x)*(1/4),y=min(.$runningScore)+0.05,label="P.value=0.05\nP.adj=0.05\nES=0.5")+
        scale_color_gradient2(low = rgb(116,173,209,max=255),
                              midpoint = median(.$x),
                              mid = "white",
                              high = rgb(253,174,97,max=255))+
        scale_x_continuous(limits = c(1,length(.$x)),expand = c(0,0))+
        scale_y_continuous(expand = c(0,0),limits = c(min(.$runningScore)-0.375,max(.$runningScore)+0.15),breaks = seq(round(min(.$runningScore),2),round(max(.$runningScore),2),0.2))+
        labs(x="",title = pathway)+theme_prism()+theme(plot.margin = unit(rep(0.5,4),"cm"),
                                       #axis.text.x = element_blank(),
                                       #axis.ticks.x = element_blank()
                                       panel.border = element_rect(size = 1,fill=NA),
                                       axis.line = element_blank()
                                       )
    }
    

    最后的图大概长这样子:

    image.png

    相关文章

      网友评论

        本文标题:个性化调整GSEAplot--第二篇

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