Reputation: 181
I really like the idea of a hexbin density plot in ggplot, and I try to use it (instead of a square-shaped bin as produced by stat_bin2d) whenever I can. However, the boundries of the hexagons are sometimes obvious. For example,
d <- ggplot(diamonds, aes(carat, price))
d + stat_binhex()
In this picture the boundaries of hexagons show up as little white lines, which sometimes interferes with my attempt to conceive the true "density" variations in the picture.
If I use stat_bin2d, the boundaries lines are not shown at all :
d <- ggplot(diamonds, aes(carat, price))
d + stat_bin2d()
So my questions are:
Why the hexagon boundaries are displayed while square boundaries aren't.
More importantly, is there a way to do stat_hexbin without showing boundary lines?
Thanks very much!
Aside: I prefer to do hexagon density plot in ggplot rather than using some other package mainly because I like the flexibility of adding other layers to it later on.
Upvotes: 4
Views: 2469
Reputation: 5532
Using the link to ggplot2 multiple stat_binhex() plots with different color gradients in one image as a reference I was able to do what you are asking with the following code:
d <- ggplot(diamonds, aes(carat, price))
d + stat_binhex(aes(colour = ..count..))
or
d <- ggplot(diamonds, aes(carat, price, colour = ..count..))
d + stat_binhex()
Upvotes: 6