首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >热图叠加密度图

热图叠加密度图
EN

Stack Overflow用户
提问于 2013-11-14 22:14:35
回答 1查看 638关注 0票数 0

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

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

到现在为止,一切都很好,因为我知道函数热图。但是,在热图上,我必须逐行绘制一个基因的表达式值的分布:

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

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

对此有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-15 06:08:49

在没有示例数据的情况下,很难确定您所追求的是什么,但可能需要使用ggplot2和geom_tile()图,如下所示(很抱歉,它没有伪装,但您可以摆弄它):

代码语言:javascript
复制
## 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()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19989546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档