这是我正在尝试开发的图表:
我有行和列坐标变量,还有三个定量变量(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 是否合适,其他部分是否正常,因为除了错误之外我无法得到任何结果。
最佳答案
这里最好用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()
关于r 中带有重叠圆圈(填充和大小)的行列热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097136/