Make Bland Altman Plots with Marginal Histograms using ggExtra

The Problem

As you know in Clinical Chemistry, we are not always writing a major paper but sometimes just preparing a short-report to answer a technical question that we've encounted at work. For shorter papers, journals often have more stringent rules about how many figures you can submit and even sometimes forbid multipanelled figures. In these situations, we might want to cram a little more into your figure than we might otherwise. In a recent submission, I wanted to produce a difference plot of immunoassay results before and after storage but I also wanted to show the distribution of the results using a histogram–but this would have counted as two separate figures.

However, thanks to some fine work by Dean Attali of UBC Department of Statistics where he works with R-legend Jenny Bryan, it is quite easy to add marginal histograms to a Bland Altman (or any other scatter) plot using the ggExtra package.

How To

Let's make some fake data for a Bland Altman plot. Let's pretend that we are measuring the same quantity by immunoassay at baseline and after 1 year of storage at -80 degrees. We'll add some heteroscedastic error and create some apparent degradation of about 20%:

Or if we plot this in the ggplot() paradigm

Now we will prepare the difference data:

In standard Bland Altman plots, one plots the difference between methods against the average of the methods, but in this case, the x-axis should be the baseline result, because that is the closest thing we have to the truth.

So that is the difference plot for the absolute difference. We can also obviously do the percent difference.

Kickin' it Old School

You can also do this in a non-ggplot() paradigm using base plotting utilities as described in this R-bloggers post.

Conclusion

And that, friends, is a way of squishing in a histogram of your sample concentrations into your difference plot which allows you to graphically display your sampling distribution and justify whether you would use parametric or non-parametric statistics to assess the extent of loss of immunoreactivity from storage.

And speaking of scatterplots

“…then the Lord your God will restore your fortunes and have compassion on you and gather you again from all the nations where he scattered you.”
Deut 30:3

0

5 thoughts on “Make Bland Altman Plots with Marginal Histograms using ggExtra”

1. EpiPete says:

Hi,

There’s an issue with the figure. The y-axis marginal histogram isn’t aligned with the data. The shift in axis limits caused by adding the 2*sd.diff hline is the problem.

1. dtholmes@mail.ubc.ca says:

Can’t believe I did not notice this. Seems only to be a problem on the first of the two figures. I will fix. Thank you for the good eye.

2. dtholmes@mail.ubc.ca says:

So it looks like you need to pre-set the ylim to include the h-lines before plotting the histogram. Thanks for noticing this error.

2. Thanks for writing this very useful post!

1. dtholmes@mail.ubc.ca says:

Thanks very much Bob!