I use a hexplot to visualize data in R. I'm wondering if I can make the number of the colors of the bins grow.

Let me give you an example:


This creates the following plot:

enter image description here

What I would like to have is smaller step in the colors thus more colors in this plot in order to indicate small differences, too.

(a solution utilizing ggplot2 would be perfect as well)


1 Answer 1


With ggplot():

x <- data.frame(x=rnorm(10000),y=rnorm(10000))

ggplot(x, aes(x,y)) + 
geom_hex() + 
scale_fill_continuous(low = "red", high = "blue",breaks=seq(5,75,5))

In geom_hex(), you can set alpha=0.5 to accomodate for some degree for overplotting. But the number of hues is defined by breaks= in scale_fill_continuous() there's only so many that it can handle though. So, your mileage may vary.

There's also scale_fill_gradient() that you can play around with.


Not the answer you're looking for? Browse other questions tagged or ask your own question.