Monday, April 22, 2013

2D plot with histograms for each dimension (2013 edition)

In 2009, I wrote about a way to show density plots along both dimensions of a plot. When I ran the code again to adapt it to a new project, it didn't work because ggplot2 has become better in the meantime. Below is the updated code. Using the gridExtra package and this hint from the ggplot2 wiki, we get this output:


Source code:

1 comment:

Adam C said...

Thanks for this. To my eyes, replacing:

stat_density(fill = NA, position="dodge")

with:

geom_line(stat="density", position="dodge")

Looks much better.