Skip to content

Conversation

hadley
Copy link
Member

@hadley hadley commented May 9, 2018

Fixes #2493

@karawoo can you please double check my logic? I think this makes sense as we should only be considering the maximum number of overlapping groups within a panel.

@hadley hadley requested a review from karawoo May 9, 2018 21:49
Copy link
Member

@karawoo karawoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great for bars/boxes/etc. but for interval geoms the vapply() fails because find_x_overlaps() sometimes returns a vector of length >1. See the following reprex which works on master but fails with this PR:

# On master
library("ggplot2")

df <- tibble::tibble(
  xmin = c(1, 3, 6),
  xmax = c(5, 7, 9),
  ymin = c(1, 1, 5),
  ymax = c(3, 4, 8),
  fill = c("a", "b", "c")
)

ggplot(df, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = fill)) +
  geom_rect(alpha = 0.8, position = position_dodge2(preserve = "single"))

With the changes from this PR:

ggplot(df, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, fill = fill)) +
  geom_rect(alpha = 0.8, position = position_dodge2(preserve = "single"))
#> Error in vapply(panels, find_x_overlaps, double(1)): values must be length 1,
#>  but FUN(X[[1]]) result is length 3

n <- max(table(find_x_overlaps(data)))
panels <- unname(split(data, data$PANEL))
if ("x" %in% names(data)) {
# Point geom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment confused me for a minute as I thought it was only running for geom_point()

@hadley
Copy link
Member Author

hadley commented May 10, 2018

Thanks for catching that - should be resolved now.

@lock
Copy link

lock bot commented Nov 6, 2018

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/

@lock lock bot locked and limited conversation to collaborators Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants