具有频率图的R热图类型图 [英] R heatmap type plot with frequency plot

查看:988
本文介绍了具有频率图的R热图类型图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个如下图:

p>

我使用ggplot2中的geom_tile()大致得到了左图,但我无法弄清楚如何生成右图和如何得到两个图



示例:

  tt<  -  structure(list (基因=结构(c(3L,1L,2L,4L,4L,4L,2L,3L,1L,3L,1L,2L,1L,2L,4L),标签= c(A (1L,5L,5L,5L,6L,6L,6L,6L,6L,6L,3L,3L,4L),肿瘤样本,4L,2L),标签= c(1,5,3,4,2,6),class =因子),效果= c(错误 ,错误,错误,错误,错误,错误,错误,废话,错误,错误,错误,错误,错误, (1L,3L,4L,5L,6L,7L,8L,9L),row.names = c(1L,3L,4L,5L,6L,7L,8L,9L) ,10L,11L,12L,13L,14L,15L,18L), class =data.frame)
ggplot(tt,aes(x = Gene,y = tumour.sample))+ geom_tile(aes(fill = Effect))+ theme(axis.text.x = element_text角度= -90,hjust = 0))

最好的方法是什么? p>

目前热图没有顶部标签,而且盒子也不是正方形。

解决方案

要获得侧面图,您可能需要转换数据。这是一个粗略的开始(使用上面的 tt 数据)

  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),' (',效应),
等级(因子(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 plot
grid.arrange(p1,p2,ncol = 2)


I am trying to create a plot like the following:

I have roughly got the left plot using geom_tile() from ggplot2, but I can't work out how to one generate the right-hand graph and how to get the two plots together.

Example:

tt <- structure(list(Gene = structure(c(3L, 1L, 2L, 4L, 4L, 4L, 2L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 4L), .Label = c("A", "B", "C", "D"), class = "factor"), tumour.sample = structure(c(1L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 3L, 3L, 4L, 4L, 2L), .Label = c("1", "5", "3", "4", "2", "6"), class = "factor"), Effect = c("missense", "missense", "missense", "missense", "missense", "missense", "missense", "nonsense", "missense", "missense", "missense", "missense", "missense", "nonsense", "missense")), .Names = c("Gene", "tumour.sample", "Effect"), row.names = c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 18L), class = "data.frame")
ggplot(tt, aes(x=Gene, y=tumour.sample)) + geom_tile(aes(fill=Effect)) + theme(axis.text.x = element_text(angle = -90, hjust = 0))

What is the best approach to do this?

At the moment the heatmap doesn't have the labels at the top and the boxes are not square as well.

解决方案

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)

这篇关于具有频率图的R热图类型图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆