r 中带有重叠圆圈(填充和大小)的行列热图

标签 r plot ggplot2 heatmap

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

enter image description here

我有行和列坐标变量,还有三个定量变量(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()

enter image description here

关于r 中带有重叠圆圈(填充和大小)的行列热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14097136/

相关文章:

python - 将 3d 钻孔轨迹转换为笛卡尔坐标并使用 matplotlib 绘制

Python - 绘制天线辐射模式

r - 将 R 中的向量运算符的 drop 永久设置为 FALSE

r - 如何为空间数据帧生成k-最近邻矩阵?

R - 最大公约数 dplyr 例程

python - 如何使用 Python 从文本文件中绘制数据

r - 绘制频率表

r - 如何在ggplot2中使用纬度和箭头绘制风向

r - 如何在 lmer 或 glmer 中预测和绘制非线性变化斜率?

r - 有没有办法将 gplots::textplot 与 tables::tabular 一起使用?