Heatmap showing two variables per cell

Viewed 472

I saw a figure someone else made that was similar to a heatmap, but they were able to show two variables by having a different sized circle in each cell, so one variable was indicated by the shading of the circle, and another by the size of the circle. Does anyone know how to make such a figure? They said they'd made it in R, but if it's possible in python I'd prefer that.

1 Answers

With this dummy dataframe with two variables var1 and var2 and associated values for color and size:

df <- expand.grid(data.frame(var1 = LETTERS[1:5],
                             var2 = letters[1:5]))
df$color= sample(2:100,25)
df$size = sample(2:100,25)

  var1 var2 color size
1    A    a    78   35
2    B    a    64   54
3    C    a    95   25
4    D    a    51   88
5    E    a    63   92
6    A    b    36    4

Using, ggplot2 in R, you can draw a "heatmap" of circles with size and different color by using geom_point and passing color and size argument into the aes of geom_point. I add geom_tile in order to draw squares around each point.

ggplot(df, aes(x= var1, y = var2))+
  geom_tile(fill = "white", color = "black")+
  geom_point(aes(color = color, size = size))+
  scale_size_continuous(range = c(1,15))

Related