Skip to content

Feature request: xend/yend defaults for geom_segment() #5140

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

Closed
teunbrand opened this issue Jan 7, 2023 · 0 comments · Fixed by #5154
Closed

Feature request: xend/yend defaults for geom_segment() #5140

teunbrand opened this issue Jan 7, 2023 · 0 comments · Fixed by #5154
Labels
feature a feature request or enhancement layers 📈

Comments

@teunbrand
Copy link
Collaborator

Arguably, a very common use-case of geom_segment() is where either x == xend or y == yend (not both though). This is the case for e.g. needle plots, lollipop charts, dumbbell plots, and probably some other plot types that I'm overlooking at the moment.

Currently, xend and yend are required aesthetics. I'm arguing that these should become optional aesthetics, where they internally default to x and y. To be explicit, I'm proposing that the GeomSegment$draw_panel method should start as follows:

data$xend <- data$xend %||% data$x
data$yend <- data$yend %||% data$y

I have thought of these drawbacks:

  • If neither xend nor yend are specified, you get 0-length line segments that don't make any sense. This might be confusing to newcomers.
  • I haven't fully pondered the impact on extensions yet. From a brief glance, a non-trivial amount of GeomSegment extensions set either xend <- x or yend <- y, so this might save a line of code there as well. I expect that not many will break, but there might be unique situations.

Some upsides:

  • It will often save you the hassle of specifying one of the two end aesthetics.
  • This will not be a change that breaks existing plots. Previously, these parameters were required, so all pre-existing plots will already have xend/yend aesthetics.
  • You have options for dodging segments (position_dodge() doesn't properly dodge segments #3617). Want to ends to dodge? Specify them. Want straight lines? Omit them.
  • A needle plot (Needle plots #3627) would become as simple as specifying:
ggplot(mpg, aes(displ, hwy, yend = 0)) +
  geom_segment()

Alternativly, we might also consider to make the required aesthetics c("x", "y", "xend|yend"). That'll throw an informative error in the first drawback case I mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant