4
votes
$\begingroup$

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:

library(hexbin)
plot(hexbin(rnorm(1000000),rnorm(1000000)))

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)

$\endgroup$

1 Answer 1

5
votes
$\begingroup$

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.

$\endgroup$
0

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