Closed
Description
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
noryend
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
oryend <- 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.