How can I apply colours different from the default blues to geom_bin2d plots?
library(ggplot2)
x <- rnorm(100000)
y <- rnorm(100000)
df <- data.frame(x,y)
p <- ggplot(df, aes(x, y))
p <- p + stat_bin2d(bins = 200)
p + scale_colour_gradientn(limits=c(0,50), breaks=c(0,10,20,30,40), colours=rainbow(4))but apparently ggplot2 just adds a second scale to the plot without actually using it. I intended to replace the default-scale...
01 Answer
You need to use scale_fill_gradientn(), since stat_bin2d has a fill aesthetic:
p + scale_fill_gradientn(limits=c(0,50), breaks=seq(0, 40, by=10), colours=rainbow(4))