美文网首页R语言ggplot2绘图R语言做生信
如何绘制两个通路中有哪些交叉基因?ggplot2

如何绘制两个通路中有哪些交叉基因?ggplot2

作者: PriscillaBai | 来源:发表于2018-12-18 15:33 被阅读15次

    这种图又称cross-talk,实验室大老板叫我画的。画完还挺有满足感的,所以把代码整理下放出来。

    输入矩阵

    假设我们整理好这样的矩阵,第一列是FC值,第二列是基因名,第三列是基因所在的通路名,其中在两个通路中都有的基因用intersect表示。

    library(ggplot2)
    library(ggrepel)
    temp<-test[which(test$X=="intersect"),]
    library(Cairo)
    CairoJPEG("crosstalk.jpeg",width=7200,height=4800,res=1200)
    ggplot(test)+geom_point(aes(x=test$Symbol,y=test$log2FoldChange.C2.C1.,colour=factor(test$X)),size=5)+
      scale_x_discrete(limits=test$Symbol)+theme_bw()+theme(panel.grid = element_blank())+
      ylab("Fold change")+
      theme(axis.text.x=element_blank())+theme(axis.ticks.x = element_blank())+theme(axis.title.x = element_blank())+
      geom_text_repel(aes(x=test$Symbol,y=test$log2FoldChange.C2.C1.,label=ifelse(test$X=="intersect",test$Symbol,"")),
                      colour="darkred",size=3,box.padding = unit(0.35, "lines"),point.padding = unit(0.3, "lines"))+
      geom_point(data=temp,aes(x=temp$Symbol,y=temp$log2FoldChange),alpha=1,size=5.1,shape=1,stroke=1,color="black")+
      theme(axis.text.y=element_text(face="bold",color="black",size=15))+theme(axis.title.y=element_text(size=14))+theme(legend.title=element_blank())
    dev.off()
    

    看起来有点乱,于是我分图层整理了一下,方便大家查阅

    输出高清图
    CairoJPEG("crosstalk.jpeg",width=7200,height=4800,res=1200)
    排列X轴顺序
    scale_x_discrete(limits=test$Symbol)
    背景为白色
    theme_bw()
    去掉网格线
    theme(panel.grid = element_blank())
    去掉X轴坐标
    theme(axis.text.x=element_blank())
    去掉X轴刻度尺
    theme(axis.ticks.x = element_blank())
    去掉X轴标题
    theme(axis.title.x = element_blank())
    在图上加基因名字(我只想给重叠的基因加,不然太乱了)
    geom_text_repel(aes(x=test$Symbol,y=test$log2FoldChange.C2.C1.,label=ifelse(test$X=="intersect",test$Symbol,"")),
                      colour="darkred",size=3,box.padding = unit(0.35, "lines"),point.padding = unit(0.3, "lines"))
    加上外面的黑圈(先做一个 只有intersect基因的数据框temp)
    temp<-test[which(test$X=="intersect"),]
    geom_point(data=temp,aes(x=temp$Symbol,y=temp$log2FoldChange),alpha=1,size=5.1,shape=1,stroke=1,color="black")
    

    相关文章

      网友评论

        本文标题:如何绘制两个通路中有哪些交叉基因?ggplot2

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