R heatmap type plot with frequency plot

前端 未结 1 344
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 03:59

I am trying to create a plot like the following: \"heatmap

I have roughly got the left plot us

相关标签:
1条回答
  • 2021-01-17 04:34

    To get the side plot, you would probably need to transform the data. Here's a rough start (using the tt data from above)

    p1<-ggplot(tt, aes(x=Gene, y=tumour.sample)) + 
        geom_tile(aes(fill=Effect)) + 
        theme(axis.text.x = element_text(angle = -90, hjust = 0)) + 
        scale_fill_discrete(guide=F) 
    
    #transform and summarize
    rs<-do.call(rbind, Map(function(a,b) {
        data.frame(s=b, i=seq_along(a), eff=sort(a))},
    lapply(split(tt, tt$tumour.sample), '[[', "Effect"), 
    levels(factor(tt$tumour.sample))))
    
    #make side plot
    p2<-ggplot(rs, aes(x=i, y=s)) + 
        geom_tile(aes(fill=eff)) +
        theme(axis.text.y=element_blank(), axis.title.y=element_blank()) 
    
    #print both plots
    grid.arrange(p1, p2, ncol=2)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题