【问题标题】:Superimpose density plots of heatmap叠加热图的密度图
【发布时间】:2013-11-14 22:14:35
【问题描述】:

我必须绘制一些基因表达值的热图。换句话说,热图的每一行代表 10 个基因的平均值,因此:

  • row1 --> mean_genes[1:10],
  • row2 --> mean_genes[11:20],
  • row3 --> mean_genes[21:30].

到这里,一切正常,因为我知道函数热图。但是,在热图上,我必须一次一行地绘制 1 个基因的表达值的分布(用一条线):

  • row1 --> gene_expression[1],
  • row2 --> gene_expression[11],
  • row3 --> gene_expression[31].

对所有行以此类推,因为最后我想逐行检查 10 个基因组的表达值以及感兴趣的基因的表达值以进行比较(通过眼睛)。但是我完全不知道如何制作如此复杂的情节。

有什么建议吗?

【问题讨论】:

  • 是的,我知道,但这只是一个想法。我不知道如何制作可重复的示例。
  • 好吧,提供一些示例数据并展示您想到的功能,然后解释为什么您尝试的方法没有产生预期的结果。没有东西可做,很难给出任何有意义的答案。
  • 查看gplot 包中的heatmap.2 函数。

标签: r plot heatmap


【解决方案1】:

如果没有示例数据,很难确定你在追求什么,但可能使用 ggplot2 和 geom_tile() 绘图如下(抱歉,它没有修饰,但你可以摆弄它):

## LIBRARY (must be installed)
require(ggplot2)
require(plyr)

## CREATE THE GENEMAP DATA
geneMap<-data.frame(1:100,expand.grid(1:10,1:10),rnorm(100,6,2))
colnames(geneMap)<-c("ID","X","Y","expr")

## APPEND THE ROWMEANS TO EACH ITEM
rowMean<-ddply(geneMap, "X" ,function(df)mean(df$expr))
geneMap<-merge(geneMap,rowMean,by="X")
colnames(geneMap)<-c("X","ID","Y","expr","rMean")

## CREATE A BASIC TILE WITH FILLED ROWS (FILL BY MEAN, ALPHA BY VALUE)
hmap<-ggplot(data=geneMap, aes(x=X,y=Y)) +        # Basic Plot
      theme_bw() +                                # Basic Theme
      geom_tile(aes(fill=rMean)) +                # Fill the tile by mean
      scale_x_continuous( breaks = 1:10,1) +      # Force ticks 1-10 on x axis
      scale_y_continuous( breaks = 1:10,1) +      # Force ticks 1-10 ony axis
      scale_fill_gradient(low="yellow", high="orange")   # Color the heatmap

hmap <- hmap + annotate("text", x = geneMap$X, y = geneMap$Y, 
                        label = round(geneMap$expr,2))  # Label each point with value

meanSummary<-unique(geneMap[,c("X","rMean")])     # Pull out the means for each row
origSummary<-geneMap[geneMap$Y==1,]               # Pull out the original "seed" vals for each row

hmap<- hmap + annotate("text", x = meanSummary$X, 
                       y = max(geneMap$Y)+1, 
                       label = round(meanSummary$rMean,2)) # Add the mean labels at row end
hmap<- hmap + annotate("text", x = min(geneMap$Y)-1,
                       y = max(geneMap$Y)+1, label = "MEANS") # Label the row

hmap<- hmap + geom_line(aes(x=origSummary$X, 
                            y=origSummary$expr*(max(origSummary$X)/max(origSummary$expr)),
                            size=3, alpha=0.6))   # Add the line plot

# Draw the map & flip is so the rows run horizontally (or not!)
hmap + coord_flip()

【讨论】:

  • 嗨,特洛伊!它工作得很好,适合我的问题。您只需添加:require(plyr)。 ;-)
猜你喜欢
  • 2016-08-25
  • 1970-01-01
  • 2013-07-08
  • 2014-03-19
  • 2020-06-01
  • 1970-01-01
  • 2016-08-23
  • 2020-03-20
  • 2017-05-30
相关资源
最近更新 更多