首页 文章

R Studio:叠加热图

提问于
浏览
0

我对编码很新,遇到了一个我无法在互联网上找到解决方案的问题 .

我有两个数据矩阵,我想将它们组合成一个热图 . 基质包含细胞的红色和绿色荧光强度 . 我希望热图颜色能够反映两种荧光强度(当两者都是低时为白色或黑色,红色为高时为红色,绿色为高时为绿色,两者为低时为黄色) .

根据红色和绿色之间的比例创建热图与我想要的类似,但不提供有关绝对荧光强度的任何信息 .

我可以制作两个单独的热图并将它们叠加在Illustrator中,但是这个1.不太优雅,2 . 不允许我聚类细胞和3.当在插图画家中使颜色透明时,红色和绿色的组合变为棕色不是黄色,两种颜色都非常微弱 .

我现在试图将我所拥有的两个值汇总为一个值 . 据我所知,这只能通过创建RGB值来实现 . 但是现在我有每个时间点的RGB值,我无法将它们变成情节 .

Code:

绘制热图中的比率:

heatmap.2(ratio_narm,
      trace="none",
      col = col,
      breaks = breaks,
      dendrogram='none',
      Rowv="NA",
      )

用ggplot绘制(融化的)RGB数据:

ggplot(data=RGB, aes(x=RGB$Timepoint, y=RGB$`Track ID`, fill=RGB$`RGB value`))

1 回答

  • 0

    你可以遵循这种方法 . 它将在两个矩阵中找到低值或高值并设置预定义值 .

    # data
    set.seed(12385)
    m1 <- matrix(runif(100),10,10)
    m2 <- matrix(runif(100),10,10)
    # thresholds
    low <- 0.2
    high <- 0.8
    # matrix with values 0 (both are low), 0.5 (both are average), 1 (both are high)
    m3 <- matrix(rep(0.5,100),10,10)
    # set the groups by filtering
    m3[ m1 < low & m2 < low ] <- 0
    m3[ m1 > high & m2 > high ] <- 1
    # low in m1, not considering m2
    m3[ m1 < low  ] <- 0.75
    # or low in m1, but normal in m2
    m3[ m1 < low & (m2 > low & m2 < high) ] <- 0.75
    # ... you can define more conditions as you like
    
    # plot the heatmap
    heatmap.2(m3,
              scale="none",trace="none",
              col = c("black","grey","red","yellow"))
    

相关问题