行列积热图与R中叠加圆(填充和大小)(row column heatmap plot with ov

2019-07-17 17:29发布

这里是我试图建立一个图表:

我有行和列的坐标变量,还有三个quatitative变量(rectheat =填充圈,circlefill =的矩形热图,circlesize =大小填充颜色热图)。 NA应通过不同的颜色(例如灰色)丢失表示。

以下是数据:

set.seed (1234)
rectheat = sample(c(rnorm (10, 5,1), NA, NA), 7*14, replace = T)

dataf <- data.frame (rowv = rep (1:7, 14), columnv = rep(1:14, each = 7),
          rectheat, circlesize = rectheat*1.5,
          circlefill =  rectheat*10 )
dataf

这里是我工作的代码:

require(ggplot2)
ggplot(dataf, aes(y = factor(rowv),x = factor(columnv))) +
      geom_rect(aes(colour = rectheat)) +
     geom_point(aes(colour = circlefill, size =circlesize))  + theme_bw()

我不知道如果geom_rect是适当的,另一部分则是细如我不能让错误以外的任何结果。

Answer 1:

这是更好地利用geom_tile (热图)。

require(ggplot2)
  ggplot(dataf, aes(y = factor(rowv),
             x = factor(columnv))) +        ## global aes
  geom_tile(aes(fill = rectheat)) +         ## to get the rect filled
  geom_point(aes(colour = circlefill, 
                   size =circlesize))  +    ## geom_point for circle illusion
  scale_color_gradient(low = "yellow",  
                       high = "red")+       ## color of the corresponding aes
  scale_size(range = c(1, 20))+             ## to tune the size of circles
  theme_bw()



文章来源: row column heatmap plot with overlayed circle (fill and size) in r