【问题标题】:row column heatmap plot with overlayed circle (fill and size) in rr中带有覆盖圆(填充和大小)的行列热图
【发布时间】:2012-12-31 03:32:19
【问题描述】:

这是我正在尝试开发的图表:

我有行和列坐标变量,还有三个定量变量(rectheat = 填充矩形热图,circlesize = 圆圈大小,circlefill = 填充颜色热图)。 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 是否合适,其他部分是否正常,因为除了错误之外我无法得到任何结果。

【问题讨论】:

  • 所有尺寸都与 rectheat 成正比,只是为了快速采样?你想要一些颜色来填充圆圈吗?
  • 是的,它只是为了快速采样,是的,颜色需要通过定量变量 circle fill 和 size 与 circlesize var 成正比来填充。

标签: r plot ggplot2 heatmap


【解决方案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()

【讨论】:

  • 感谢 agstudy,有没有办法按比例增加与单元格大小相比看起来更小的圆圈大小
  • @shNIL 增加看起来很小?对不起,我不明白。这里的单元格大小是固定的,你能改一下吗?
  • 圆圈看起来很小,我希望它们更大(按比例偏离航线)
  • @jon geom_circle?我还不知道这个。
  • @shNIL 如果您更改使用 shape =21 作为 geom_point 怎么办? geom_point(aes(color = circlefill, size =circlesize,fill=circlefill),shape = 21)
猜你喜欢
  • 1970-01-01
  • 2021-09-06
  • 2020-12-12
  • 2019-03-03
  • 2020-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多