2

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.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Colin
  • 10,447
  • 11
  • 46
  • 54
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Mar 10 '20 at 20:58
  • 1
    [corrplot](https://stackoverflow.com/questions/26202670/how-to-use-corrplot-with-simple-matrices) – rawr Mar 10 '20 at 21:40
  • Can you use corrplot with the data in dc37's answer? corrplot seems to still just plot a single variable, but showing the absolute value with the size of the circle and pos/neg with the color scale. – Colin Mar 10 '20 at 23:13

1 Answers1

3

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

dc37
  • 15,840
  • 4
  • 15
  • 32