Representing density in two dimensions

I’ll be subbing today for Chris, as we continue to explore some ggplot2 basics. Today, imagine that you have data distributed in two dimensions, and that you would like to convey differences in point density over space.

As with many things, this is fairly easy to do with ggplot2, but it’s not quite as straightforward as it relies on the use of a “stat,” as opposed to a “geom.” In this case, we use stat_density2d (naturally), and encode our statistic of interest (density) into an aesthetic variable by use of ..level.. .

By d-sparks

Tags: ggplot2 rstats graphics basics