I can generate a density plot of 1D data with:
qplot(mydatapoints, geom='density')
I’ve also seen plenty of examples of heatmap grids, but these are more akin to histograms for 1D data in that data goes into discrete buckets instead of showing a smooth curve.
Can I plot something similar to the 1D density but for 2D data, with (say) something like hue/saturation/lightness to represent the density?
I think you want a 2D density estimate, which is implemented by
kde2din theMASSpackage.via
MASSand base R:via
ggplot(geom_density2d()callskde2d())I find
filled.contourmore attractive, but it’s a big pain to work with if you want to modify anything because it useslayoutand takes over the page layout. Building on Brian Diggs’s answer, which fills in colours between the contours: here’s the equivalent with different alpha levels, with transparent points added for comparison.