Transformation of axes in R

As a general rule, you should not transform your data to try to fit a linear model. But proportions can be tricky. If the proportion data do not arise from a binomial process (e.g., proportion of a leaf consumed by a caterpillar), then transformation is still the best option. In an excellent paper, David Warton* and Francis Hui propose that the conventional transformation for proportion data (i.e., arcsine square root) is asinine, particularly if you have binomial data, and that the logit transformation is preferable for non-binomial proportion data.

The objective of this post is simply to demonstrate how to transform the axes of plots in R, but the context of the example is the logit transformation of non-binomial proportion data. First, we need to generate some data.

The logit transformation is -infinity at 0 and infinity at 1, but adding a small amount (eps in code above) to both the numerator and denominator of the transformation solves that problem.

Next we run a simple linear model and calculate the predicted means and confidence intervals.

The plotrix package includes a function for easily plotting points with error bars. The code below produces a figure with the transformed response variable.

The transformed axis allows the reader to infer treatment effects, but is not easily interpreted. Also, the plotCI( ) function is based on a scatter plot and requires numeric input for both x- and y-variables. But both the transformed y-axis and the mislabeled x-axis are easily changed. The general approach is to tell R to exclude one or both of the axes when drawing the plot and then use the axis( ) function to customize the axes by telling R which labels to use and where to put them. In the case of the transformed y-axis, we want labels that range from 0 to 1 and we will put those labels at the value of the corresponding logit transformation.

We exclude the axes from the plot with the argument axes=F and add our custom axes at the bottom, axis(1), and left, axis(2), of the plot.

The back-transformed axis reveals a few key properties of the transformation (i.e., symmetry around 0.5, compressed scale in the middle of the distribution, and spread scale at the ends of the distribution), but obscures the fact that the confidence intervals are not symmetric around the mean.

Alternatively, you can back transform the predicted values from the linear model.

And plot them on the original scale.

This version provides the more familiar linear y-axis and clearly illustrates the asymmetry in the confidence intervals, but does not confront the reader with the key properties of the transformation.

*David Warton clearly recognizes that good science need not always be so serious as evidenced by his YouTube video promoting his new R package.

The following two tabs change content below.

Latest posts by Travis Hinkelman (see all)

3 thoughts on “Transformation of axes in R

  1. Pingback: Spacing of multi-panel figures in R | Datavore Consulting | Blog

  2. Pingback: Count data and GLMs: choosing among Poisson, negative binomial, and zero-inflated models | Datavore Consulting | Blog

  3. Pingback: Late to the ggplot2 party | Datavore Consulting | Blog

Leave a Reply