In ggplot, how can I get two legends ("gradient" type) for stat_bin2d?

Viewed 219

Here I have two 'clusters', and just one legend.

How can I get two "density" legends with two different color gradients?

I have tried group but it does not work.

enter image description here

The following code generated the above graph:

library(ggplot2)

df <- data.frame(x=c(rnorm(1000,1,.1),rnorm(1000,3,.1)),
                 y=c(rnorm(1000,1,1),rnorm(1000,3,1)),
                 type=c(rep('a',1000),rep('b',1000)))

plot( ggplot(df) + 
      stat_bin2d(aes(x,y,fill=..density..,group='type')))
2 Answers
Related