I was just browsing the web today and stumbled on an overview of data visualization in R. As I was scrolling the page something caught my eye: a hexbin plot. I had never heard of such a plot before.
To create a hexbin plot in base R with
plot() you need to install the
Then you can load the library and create your hexbin object setting
What a great way to visualize bivariate frequency data and avoid overplotting issues. Then, I thought: does
ggplot2 have a geom for that?
It turns out it’s a stat. But, yes, yes it does. In this case you will not need to install/ load the
hexbin package. Just apply
stat_binhex() to your plot.
In both the
ggplot2 approaches you can tweak the bin size to adjust the desired granularity of the plot.
And since I was poking around on the ggplot2 documentation I also discovered another stat to use to avoid overplotting. This time when working with two categorical variables: