Sparhawk
Sparhawk

Reputation: 1677

Can I use log whiskers on a log-scale boxplot?

When I plot a boxplot with a log scale, the whiskers are based on the un-logged data.

x <- rlnorm(n=50, meanlog=0, sdlog=1)
library('beeswarm')
beeswarm(x, log=TRUE)
boxplot(x, add = TRUE, outline = FALSE)

Of course, if I manually log the data first, then the whiskers reflect this transformation.

beeswarm(log(x))
boxplot(log(x), add = TRUE, outline = FALSE)

Is it possible to have the axis from the first graph with the whiskers of the second? That is, can I plot the unlogged data on a log axis, but still have "logged" whiskers?

Upvotes: 2

Views: 2854

Answers (1)

Marius
Marius

Reputation: 60070

You can take the values calculated by boxplot(log(x)) and transform them back onto the original scale of x. I'm not sure how meaningful the resulting plot is though:

x <- rlnorm(n=50, meanlog=0, sdlog=1)
library('beeswarm')
beeswarm(x, log=TRUE)
box = boxplot(log(x), add = FALSE, plot = FALSE, outline = FALSE)
box$stats = exp(box$stats)
box$conf = exp(box$conf)
bxp(box, add=TRUE)

enter image description here

Upvotes: 1

Related Questions