11
votes

How can I adjust my Y axis in order to ignore outliers, like in this post, but in a more challenging case where I have 4 boxplots and a "free faceting" layout?

p <- ggplot(molten.DF,aes(x=class,y=SOC,fill=class)) + geom_boxplot() + facet_grid(layer~.,scales="free",space="free")

As you can see on my figure, considering outliers in the Y axis range make the boxes more difficult to read. No importance if some outliers are still visible in the result, but I would like to really focus on the boxes!

boxplot with free scale, all outliers are (unfortuately) visibles

1
If you post a reproducible example for us to work with it becomes much easier for us to help you.Eric Fail

1 Answers

2
votes

It obviously depends on what you consider an outlier. If it's possible for you to calculate it, you can set your ylim at this value an let those points out of the chart.

For example, if you assume that the upper and lower limits are Q3 + 1.5 IQR and Q1 - 1.5 IQR, and this is the way boxplots usually have its outliers limit calculated, you would have:

upper.fence <- quantile(x)[4] + 1.5*IQR(x)
lower.fence <- quantile(x)[2] - 1.5*IQR(x)

Then you can use these limits as the y range of values:

my.ggplot + coord_cartesian(ylim=c(lower.fence, upper.fence))

The procedure you use to get your upper and lower limits can change, but the use of the limits is the same.