-
Notifications
You must be signed in to change notification settings - Fork 2.1k
collapsing to unique 'x' values in geom_violin with draw_quantiles #4455
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
Here's a symmetric example. df <- data.frame(x = 1, y = c(0, 0, 5, 10, 10))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), bw = 0.1) |
df <- data.frame(x = 1, y = c(0, 0.25, 0.5, 0.75, 5))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), adjust=1.1) Should the warning maybe be turned into a more useful warning hinting the user at |
I think quantitively, this only makes a difference, if ever, when the quantile is in a region of zero density, in which case its exact placement is not visible anyway. So it would be safe to use ecdf <- stats::approxfun(dens, data$y, ties = "ordered") to get rid of this warning, as in create_quantile_segment_frame <- function(data, draw_quantiles) {
dens <- cumsum(data$density) / sum(data$density)
ecdf <- stats::approxfun(dens, data$y, ties = "ordered")
ys <- ecdf(draw_quantiles) # these are all the y-values for quantiles
# Get the violin bounds for the requested quantiles.
violin.xminvs <- (stats::approxfun(data$y, data$xminv))(ys)
violin.xmaxvs <- (stats::approxfun(data$y, data$xmaxv))(ys)
# We have two rows per segment drawn. Each segment gets its own group.
ggplot2:::new_data_frame(list(
x = ggplot2:::interleave(violin.xminvs, violin.xmaxvs),
y = rep(ys, each = 2),
group = rep(ys, each = 2)
))
}
assignInNamespace("create_quantile_segment_frame", create_quantile_segment_frame, "ggplot2")
df <- data.frame(x = 1, y = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), bw = 0.1) |
Would you be interested in providing a PR that fixes this? |
@thomasp85 sure! I still have to think about the best way to test this, but I think I know how to approach it. |
@thomasp85 #4654 is ready for review. |
I receive the warning
with this code:
The warning does not appear with
so it is not a problem of the structure (including any potential duplicates) of the data.
The text was updated successfully, but these errors were encountered: