Representing density in two dimensions

November 21, 2012
By

(This article was first published on is.R(), and kindly contributed to R-bloggers)

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.. .

To leave a comment for the author, please follow the link and comment on his blog: is.R().

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.