9
$\begingroup$

In the boxplot() function in R, there exists the log = argument for specifying whether or not an axis should be on the log scale.

To me, if I choose this option (specify log = "y" as an argument), the shape of the box-plot should look the same as if I manually transform the data first with the log, then plot that log-transformed data (I recognize the labels on the axis will be different, but I'm referring to the shape of the plot). However, this isn't the case.

Here is a simple working example:

set.seed(923489)
data <- rlnorm(300, meanlog = 0, sdlog = 1)
boxplot(data) # Highly skewed right raw data
boxplot(data, log="y") # Data on log scale; less right-skewed
boxplot(log10(data)) # Log base 10-transform data; shape not the same as when specify log="y"
boxplot(log(data)) # Natural log and base 10 give same shape plot (just different axis labels)

Why is this so?

$\endgroup$
1
  • 2
    $\begingroup$ One calculates the boxplot in original units then draws that on the log scale, the other calculates the boxplot on the log-scale then draws it. The two things are different any time you get something that's not purely based on the individual quantiles (the fences, and hence the whiskers are based on linear functions of quantiles) $\endgroup$
    – Glen_b
    Commented May 7, 2016 at 17:11

2 Answers 2

7
$\begingroup$

Obviously, the box with the median "belt" looks the same. The difference are the whiskers. In the default settings, ?boxplot tells us that

If ‘range’ is positive, the whiskers extend to the most extreme data point which is no more than ‘range’ times the interquartile range from the box.

range is positive, namely 1.5 in the default. So do the whiskers extend 1.5 times the box, but in which scale? If you call boxplot(data, log="y"), it is 1.5 on the unscaled data; thus the lower whisker becomes longer. If you call boxplot(log(data)) the whiskers are necessarily symmetric.

$\endgroup$
2
  • $\begingroup$ Thank you. It's not clear to me, then, what's the "most correct" way to represent the data. This post (which is for Stata, not R, but discusses the same issue) seems to imply the best practice would be to first log-transform the data, then manually re-label the box-plot in terms of the original units: stata.com/support/faqs/graphics/… Thoughts on this approach? $\endgroup$
    – Meg
    Commented May 7, 2016 at 22:02
  • 2
    $\begingroup$ @Meg I think it would depend on whether you think the whiskers (representing the range) should be the same length in log-space or unscaled. Given that you are log-transforming the data, the former probably makes more sense. $\endgroup$
    – Hao Ye
    Commented May 8, 2016 at 8:06
4
$\begingroup$

From ?boxplot, you can read:

range

this determines how far the plot whiskers extend out from the box. If range is positive, the whiskers extend to the most extreme data point which is no more than range times the interquartile range from the box. A value of zero causes the whiskers to extend to the data extremes.

The default when plotting a boxplot, range=1.5, means that the whiskers will extend 1.5 times the interquartile range above the third quartile and below the first quartile; all other points will be labeled as outliers.

The differences you are seeing are based on the fact that log transformation of the data does not maintain the normalized distance of a point from the third or first quartile; as expected with your data, after log-transformation you have fewer outliers with very high values and more outliers with low values.

$\endgroup$
1
  • $\begingroup$ Thank you for your comment, which is essentially equivalent to that above. I chose as the "correct" answer that with the most up-votes, but appreciate your input as well. $\endgroup$
    – Meg
    Commented May 9, 2016 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.