5

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

在此处输入图像描述

我有行和列坐标变量,还有三个定量变量(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 是否合适,其他部分是否正常,因为除了错误之外我无法得到任何结果。

4

1 回答 1

13

这里最好使用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()

在此处输入图像描述

于 2012-12-31T04:15:12.387 回答