ggridges 山峦图

library(ggplot2)
library(ggridges)
library(RColorBrewer)
##添加线条
A2lineData1=data.frame(x=c(0.39,0.39),y=c(1,1.7))
A2lineData2=data.frame(x=c(0.42,0.42),y=c(1,1.7))
D5lineData1=data.frame(x=c(0.39,0.39),y=c(2,2.7))
D5lineData2=data.frame(x=c(0.419,0.419),y=c(2,2.7))
TM1lineData1=data.frame(x=c(0.39,0.39),y=c(3,3.7))
TM1lineData2=data.frame(x=c(0.42,0.42),y=c(3,3.7))
##创建pdf文件
pdf('exon_GCCount.pdf',width = 6,height = 3)
mergeData=read.table("./exon_GC_plot.txt")
##颜色映射
Colormap<- colorRampPalette(rev(brewer.pal(11,'Spectral')))(32)
ggplot(mergeData,aes(x=V1,y=V3,color=V2))+
  geom_density_ridges_gradient(aes(fill=..density..),scale =0.6, size = 1)+
  theme(
    panel.background = element_blank(),
    axis.text.y = element_text(size=15),
    axis.text.x=element_text(size=12),
    axis.title.x = element_text(size=15),
    plot.margin=unit(c(1,1,1,1),'lines'),
    axis.ticks.y = element_blank()
    )+
  scale_y_discrete(expand = c(0,0))+
  scale_x_continuous(expand = c(0,0))+
  labs(x="GC count",y="")+
  scale_fill_gradientn(colours=Colormap,name = "Density")+
  scale_color_discrete(labels=c('Alt.exon','Con.exon'))+
##修改图例,和图例显示内容
  guides(
    color=guide_legend(
      title="Type",
      title.theme = element_text(size=14),
      label.theme = element_text(size=12),
      order = 1
    )
  )+
  guides(
    fill=guide_colorbar(
      title.theme = element_text(size=14),
      label.theme = element_text(size=12),
      order = 2
    )
  )+
##绘制线条
  geom_line(data=A2lineData1,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  geom_line(data=A2lineData2,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  geom_line(data=D5lineData1,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  geom_line(data=D5lineData2,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  geom_line(data=TM1lineData1,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  geom_line(data=TM1lineData2,aes(x,y), inherit.aes =FALSE,linetype="dashed")+
  annotate(geom = 'text',x = 0.41,y=1.7,label="***")+
  annotate(geom = 'text',x = 0.41,y=2.7,label="***")+
  annotate(geom = 'text',x = 0.48,y=3.6,label="***")
dev.off()

参考

Last updated