Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

row column heatmap plot with overlayed circle (fill and size) in r

Here is a graph I am trying to develop:

enter image description here

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.

like image 570
shNIL Avatar asked Dec 31 '12 03:12

shNIL


1 Answers

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

enter image description here

like image 171
agstudy Avatar answered Nov 15 '22 04:11

agstudy