Site icon R-bloggers

Representing density in two dimensions

[This article was first published on is.R(), and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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

https://gist.github.com/4063489
To leave a comment for the author, please follow the link and comment on their blog: is.R().

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.