在r中有重叠圆(填充和大小)的行列热图图 [英] row column heatmap plot with overlayed circle (fill and size) in r

查看:392
本文介绍了在r中有重叠圆(填充和大小)的行列热图图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在开发的图表:

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

以下是我工作的代码:

<$ (colorf,aes(y = factor(rowv),x = factor(columnv)))
geom_rect(aes(color = rectheat))+
geom_point(aes(color = circlefill,size = circlesize))+ theme_bw()

我不确定geom_rect是否合适,其他部分是否正常,因为除错误外我无法获得任何结果。

解决方案

这里最好使用 geom_tile (heatmap)。

  require(ggplot2)
ggplot(dataf,aes(y = factor(rowv),
x = factor (columnv)))+ ## global aes
geom_tile(aes(fill = rectheat))+ ##得到rect填充的
geom_point(aes(color = circlefill,
size = circlesize ))+ ## geom_point for circle illusion
scale_color_gradient(low =yellow,
high =red)+ ##相应aes的颜色
scale_size(range = c(1 ,20))+ ##来调整圆圈的大小
theme_bw()

< img src =https://i.stack.imgur.com/Bw2du.pngalt =在这里输入图片描述>


Here is a graph I am trying to develop:

I have row and column coordinate variables, also three quatitative variables (rectheat = to fill the rectangle heatmap,circlesize = size of circles, circlefill = fill color heatmap). NA should be missing represented by a different color (for example gray color).

The following is data:

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

Here is code that I worked on:

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()

I am not sure if geom_rect is appropriate and other part is fine as I could not get any results except errors.

解决方案

Here it is better to use geom_tile (heatmap).

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中有重叠圆(填充和大小)的行列热图图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆