Using R and ggplot2 to draw a scatterplot with the two marginal boxplotsDrawing a scatterplot with the marginal boxplots (or marginal histograms or marginal density plots) has always been a bit tricky (well for me anyway). The approach I take here is, first, to draw the three separate plots using ggplot2:
- the scatterplot;
- the horizontal boxplot to appear in the top margin;
- the vertical scatterplot to appear in the right margin;
To draw the following chart, I borrowed and modified code from here and here. The final code and data are available on GitHub.