-
Notifications
You must be signed in to change notification settings - Fork 2.1k
boxplot computation fails when setting scale limits #3548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I believe the issue is more fundamental than scale limits. Consider the following code: library(ggplot2)
library(nycflights13)
ggplot(data = weather, mapping = aes(x = factor(month), y = temp)) +
geom_boxplot() Using whereas using
#> Warning: Computation failed in `stat_boxplot()`:
#> missing values and NaN's not allowed if 'na.rm' is FALSE cc @ismayc |
I think I found the problem. It's in this line: Line 55 in 10fa001
It should read Reprex: library(ggplot2)
library(rlang)
library(nycflights13)
# doesn't work
ggplot(data = weather, mapping = aes(x = factor(month), y = temp)) +
geom_boxplot()
#> Warning: Computation failed in `stat_boxplot()`:
#> missing values and NaN's not allowed if 'na.rm' is FALSE # fix setup_data() function of StatBoxplot
StatBoxplot$setup_data <- function(data, params) {
data <- ggplot2:::flip_data(data, params$flipped_aes)
data$x <- data$x %||% 0
data <- ggplot2:::remove_missing(
data,
na.rm = FALSE,
vars = "y",
name = "stat_boxplot"
)
flip_data(data, params$flipped_aes)
}
# now it works
ggplot(data = weather, mapping = aes(x = factor(month), y = temp)) +
geom_boxplot()
#> Warning: Removed 1 rows containing missing values (stat_boxplot). Created on 2019-10-06 by the reprex package (v0.3.0) cc @thomasp85 |
Thomas, while we're at it, is this line correct, or should it read Line 54 in 10fa001
It looks like with the current settings it's impossible to suppress the warning about missing values. library(ggplot2)
library(rlang)
library(nycflights13)
# fix setup_data() function of StatBoxplot
StatBoxplot$setup_data <- function(data, params) {
data <- ggplot2:::flip_data(data, params$flipped_aes)
data$x <- data$x %||% 0
data <- ggplot2:::remove_missing(
data,
na.rm = FALSE,
vars = "y",
name = "stat_boxplot"
)
flip_data(data, params$flipped_aes)
}
# warning doesn't get suppressed
ggplot(data = weather, mapping = aes(x = factor(month), y = temp)) +
geom_boxplot(na.rm = TRUE)
#> Warning: Removed 1 rows containing missing values (stat_boxplot). StatBoxplot$setup_data <- function(data, params) {
data <- ggplot2:::flip_data(data, params$flipped_aes)
data$x <- data$x %||% 0
data <- ggplot2:::remove_missing(
data,
na.rm = params$na.rm,
vars = "y",
name = "stat_boxplot"
)
flip_data(data, params$flipped_aes)
}
# now the warning gets suppressed
ggplot(data = weather, mapping = aes(x = factor(month), y = temp)) +
geom_boxplot(na.rm = TRUE) Created on 2019-10-06 by the reprex package (v0.3.0) |
@clauswilke I don't know if it was intended that way (hardcoding the As for the cause of the original issue, it is actually much more complicated and is due to the new |
I think hardcoding |
Thank you for fixing this so promptly. I would like to give credit to my student Nouhaila @nouny for finding the error with the |
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/ |
Before 10fa001, this code produced the following image:
After 10fa001, it now produces a blank plot with this warning:
cc @thomasp85
The text was updated successfully, but these errors were encountered: