You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Whiskers and outliers for geom_boxplot with transformed scale #3336
Boxplot whiskers and outliers seem to be incorrect when using geom_boxplot with a transformed scale. It probably affects notches too, but I haven't checked.
The hinges are fine, which makes sense—monotonic transformations preserve quantiles.
You're right, boxplots are calculated based on the transformed values, which affects the calculation of outliers. However, StatBoxplot$compute_group() has access to the x and y scales (and their transformations), so it is possible to change this.
It's worth noting that this (surprise at Stats being calculated on transformed values) has been reported several times (#2880, #2804), and at least once it was deemed as a won't-fix: #2804 (comment)
Ah, sorry I missed those issues—I only searched for boxplot related ones.
Computing stats on the transformed values is potentially quite reasonable from a statistical perspective. If that's the way this goes, I would then just suggest a documentation update to note the behaviour since it's a bit surprising.
This is common confusion in ggplot2: Many people try to use scales for things that should be done in coords. Setting axis limits without dropping data points is another common issue.
If that's true, it should be much easier to make a pretty looking plot with coord_trans() - right now the defaults don't produce the plot most people are looking for, xlim and ylim parameters aren't named the same as coord_cartesian(), non-default axis expansion isn't possible (#3338 and #2990), second axes aren't well-supported (#2990), and some of the nice things you can do like use NA as one of the limits aren't possible in coords (#2907). Even using breaks = scales::log_breaks() doesn't really work in coord_trans().
Activity
paleolimbot commentedon May 20, 2019
You're right, boxplots are calculated based on the transformed values, which affects the calculation of outliers. However,
StatBoxplot$compute_group()has access to the x and y scales (and their transformations), so it is possible to change this.https://github.com/tidyverse/ggplot2/blob/master/R/stat-boxplot.r#L82-L85
paleolimbot commentedon May 21, 2019
The only other place I can find a
Statthat backtransforms a range isstat_function(): https://github.com/tidyverse/ggplot2/blob/master/R/stat-function.r#L93-L111https://github.com/paleolimbot/ggplot2/blob/1f6f0cb4462aa9e3b5f51dc7fd594073e78351da/R/stat-function.r#L93-L111
paleolimbot commentedon May 27, 2019
It's worth noting that this (surprise at
Stats being calculated on transformed values) has been reported several times (#2880, #2804), and at least once it was deemed as a won't-fix: #2804 (comment)mbertolacci commentedon May 27, 2019
Ah, sorry I missed those issues—I only searched for boxplot related ones.
Computing stats on the transformed values is potentially quite reasonable from a statistical perspective. If that's the way this goes, I would then just suggest a documentation update to note the behaviour since it's a bit surprising.
clauswilke commentedon Jun 1, 2019
This topic came up at Lee Wilkinson's talk yesterday at SDSS 2019: Stats are computed on the transformed values. If you want the stats to be calculated on the original values then you need to work with a transformed coordinate system: https://ggplot2.tidyverse.org/reference/coord_trans.html
This is common confusion in ggplot2: Many people try to use scales for things that should be done in coords. Setting axis limits without dropping data points is another common issue.
paleolimbot commentedon Jun 2, 2019
If that's true, it should be much easier to make a pretty looking plot with
coord_trans()- right now the defaults don't produce the plot most people are looking for,xlimandylimparameters aren't named the same ascoord_cartesian(), non-default axis expansion isn't possible (#3338 and #2990), second axes aren't well-supported (#2990), and some of the nice things you can do like useNAas one of the limits aren't possible in coords (#2907). Even usingbreaks = scales::log_breaks()doesn't really work incoord_trans().Created on 2019-06-02 by the reprex package (v0.2.1)
lock commentedon Dec 28, 2019
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
geom_box()andscale_x_log10()/scale_y_log10()produce incorrect whiskers/outliers. #6706 as a duplicate of this issue