这是我想要开发的图表:
我有行和列坐标变量,还有三个定量变量(rectheat =填充矩形热图,circleize =圆的大小,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是否合适,其他部分没问题,因为除了错误之外我无法得到任何结果。
答案 0 :(得分:10)
最好使用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()