Skip to content

Commit d4db080

Browse files
authored
Optional segment end (#5154)
* Make one of xend/yend optional * Add NEWS bullet * Reoxygenate
1 parent 7c59ba6 commit d4db080

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ggplot2 (development version)
22

3+
* You can now omit either `xend` or `yend` from `geom_segment()` as only one
4+
of these is now required. If one is missing, it will be filled from the `x`
5+
and `y` aesthetics respectively. This makes drawing horizontal or vertical
6+
segments a little bit more convenient (@teunbrand, #5140).
7+
38
* New `plot.tag.location` in `theme()` can control placement of the plot tag
49
in the `"margin"`, `"plot"` or the new `"panel"` option (#4297).
510

R/geom-segment.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ geom_segment <- function(mapping = NULL, data = NULL,
102102
#' @usage NULL
103103
#' @export
104104
GeomSegment <- ggproto("GeomSegment", Geom,
105-
required_aes = c("x", "y", "xend", "yend"),
105+
required_aes = c("x", "y", "xend|yend"),
106106
non_missing_aes = c("linetype", "linewidth", "shape"),
107107
default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = NA),
108108
draw_panel = function(self, data, panel_params, coord, arrow = NULL, arrow.fill = NULL,
109109
lineend = "butt", linejoin = "round", na.rm = FALSE) {
110+
data$xend <- data$xend %||% data$x
111+
data$yend <- data$yend %||% data$y
110112
data <- check_linewidth(data, snake_class(self))
111113
data <- remove_missing(data, na.rm = na.rm,
112114
c("x", "y", "xend", "yend", "linetype", "linewidth", "shape"),

man/geom_segment.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)