Skip to content

Commit

Permalink
Optional segment end (#5154)
Browse files Browse the repository at this point in the history
* Make one of xend/yend optional

* Add NEWS bullet

* Reoxygenate
  • Loading branch information
teunbrand committed May 8, 2023
1 parent 7c59ba6 commit d4db080
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ggplot2 (development version)

* You can now omit either `xend` or `yend` from `geom_segment()` as only one
of these is now required. If one is missing, it will be filled from the `x`
and `y` aesthetics respectively. This makes drawing horizontal or vertical
segments a little bit more convenient (@teunbrand, #5140).

* New `plot.tag.location` in `theme()` can control placement of the plot tag
in the `"margin"`, `"plot"` or the new `"panel"` option (#4297).

Expand Down
4 changes: 3 additions & 1 deletion R/geom-segment.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ geom_segment <- function(mapping = NULL, data = NULL,
#' @usage NULL
#' @export
GeomSegment <- ggproto("GeomSegment", Geom,
required_aes = c("x", "y", "xend", "yend"),
required_aes = c("x", "y", "xend|yend"),
non_missing_aes = c("linetype", "linewidth", "shape"),
default_aes = aes(colour = "black", linewidth = 0.5, linetype = 1, alpha = NA),
draw_panel = function(self, data, panel_params, coord, arrow = NULL, arrow.fill = NULL,
lineend = "butt", linejoin = "round", na.rm = FALSE) {
data$xend <- data$xend %||% data$x
data$yend <- data$yend %||% data$y
data <- check_linewidth(data, snake_class(self))
data <- remove_missing(data, na.rm = na.rm,
c("x", "y", "xend", "yend", "linetype", "linewidth", "shape"),
Expand Down
3 changes: 1 addition & 2 deletions man/geom_segment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4db080

Please sign in to comment.