2

I am creating several boxplots in ggplot2 with a log10 scale using

coord_trans(y="log10")

It is important that only the scale and not the data itself is log-transformed. One data set includes zero values, which is creating -inf values so that the boxplot cannot be drawn on a log-transformed scale.

I have tried to use

scale_y_continuous(trans=pseudo_log_trans(base=10))

However, this makes changes to the data instead of the scale. Outliers of the boxplot change and the boxplot stats extracted through ggplot_build(examplefig)$data are different from the original data.

Is there any way to create a boxplot in ggplot2 with a log10 scale and data including zero values? There should be no transformation of the data itself and outliers should be displayed like in the boxplot with the original data.

This is the very first question I ask here and I am new to R, so I hope the question is clear.

Boxplot with original data, no log transformation

Boxplot using scale_y_continuous(trans=pseudo_log_trans(base=10))

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Boxfish
  • 21
  • 1
  • The log (or pseudo log) transformation changes the scale but that actually changes what would be considered an outlier. The log scale is a multiplicative scale, not additive. The high outliers on your untransformed data are no longer outliers because they are inside the 1.5*interquartile range of the pseudo log transformed data (inside the range of the whiskers). I think the appearance of the boxplot under the transformed scale is as it should be. – qdread Dec 12 '19 at 13:32
  • Thanks for your quick reply! In all the other boxplots I made with coord_trans(y="log10") from data sets without zero values, outliers are the same with and without log transformation. This is why I attempted the same appearance in the data sets including zeros.. – Boxfish Dec 12 '19 at 13:47
  • There must be enough zeroes in there to change the position of the interquartile range. It would be helpful to have your data so that we can reproduce your example rather than looking at images of the boxplots you drew. See [these guidelines for making a reproducible example in R](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – qdread Dec 12 '19 at 16:31

0 Answers0