Site icon R-bloggers

Plotting data and distribution simultaneously (with ggplot2)

[This article was first published on gRaphics!, 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.
Ever wanted to see at a glance the distribution of your data across different axes? It happens often to me, and R allows to build a nice plot composition – This is my latest concoction. I used ggplot2 here, but equivalent graphics can be made using either base graphics, or lattice.

The set is the usual ‘iris’, the central plot has petal length and width along the X/Y axes – I  used a customised color palette so as to be friendlier to color-blind people. On the left and at the top of the main plot, the density distribution of the whole set (grey) and by subspecies.

Well, I hope the code is clear – this time I commented it a bit more…

To leave a comment for the author, please follow the link and comment on their blog: gRaphics!.

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.