From d9294c89b4bfef8a8259efaaed73498739e4c7e9 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Mon, 1 Jul 2024 10:45:04 +0900 Subject: [PATCH 1/2] Expose position arg on geom_hline() and geom_vline() --- R/geom-hline.R | 3 ++- R/geom-vline.R | 3 ++- man/geom_abline.Rd | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/R/geom-hline.R b/R/geom-hline.R index 924b41f40a..6b80d0bb08 100644 --- a/R/geom-hline.R +++ b/R/geom-hline.R @@ -4,6 +4,7 @@ NULL #' @export #' @rdname geom_abline geom_hline <- function(mapping = NULL, data = NULL, + position = "identity", ..., yintercept, na.rm = FALSE, @@ -29,7 +30,7 @@ geom_hline <- function(mapping = NULL, data = NULL, mapping = mapping, stat = StatIdentity, geom = GeomHline, - position = PositionIdentity, + position = position, show.legend = show.legend, inherit.aes = FALSE, params = list2( diff --git a/R/geom-vline.R b/R/geom-vline.R index 2705093f05..85cacf3e63 100644 --- a/R/geom-vline.R +++ b/R/geom-vline.R @@ -4,6 +4,7 @@ NULL #' @export #' @rdname geom_abline geom_vline <- function(mapping = NULL, data = NULL, + position = "identity", ..., xintercept, na.rm = FALSE, @@ -29,7 +30,7 @@ geom_vline <- function(mapping = NULL, data = NULL, mapping = mapping, stat = StatIdentity, geom = GeomVline, - position = PositionIdentity, + position = position, show.legend = show.legend, inherit.aes = FALSE, params = list2( diff --git a/man/geom_abline.Rd b/man/geom_abline.Rd index 9e13bc3de8..8fd63ae8e0 100644 --- a/man/geom_abline.Rd +++ b/man/geom_abline.Rd @@ -19,6 +19,7 @@ geom_abline( geom_hline( mapping = NULL, data = NULL, + position = "identity", ..., yintercept, na.rm = FALSE, @@ -28,6 +29,7 @@ geom_hline( geom_vline( mapping = NULL, data = NULL, + position = "identity", ..., xintercept, na.rm = FALSE, @@ -89,6 +91,19 @@ a warning. If \code{TRUE}, missing values are silently removed.} It can also be a named logical vector to finely select the aesthetics to display.} +\item{position}{A position adjustment to use on the data for this layer. This +can be used in various ways, including to prevent overplotting and +improving the display. The \code{position} argument accepts the following: +\itemize{ +\item The result of calling a position function, such as \code{position_jitter()}. +This method allows for passing extra arguments to the position. +\item A string naming the position adjustment. To give the position as a +string, strip the function name of the \code{position_} prefix. For example, +to use \code{position_jitter()}, give the position as \code{"jitter"}. +\item For more information and other ways to specify the position, see the +\link[=layer_positions]{layer position} documentation. +}} + \item{xintercept, yintercept, slope, intercept}{Parameters that control the position of the line. If these are set, \code{data}, \code{mapping} and \code{show.legend} are overridden.} From ea8a5dd11514464a922f3e7e3bce19fc45852296 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Mon, 1 Jul 2024 16:46:30 +0900 Subject: [PATCH 2/2] Add a NEWS bullet [skip ci] --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index d553c7f924..f739f2b4a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -99,6 +99,8 @@ the `nbin` argument (@teunbrand, #5882, #5036) * `after_stat()` and `after_scale()` throw warnings when the computed aesthetics are not of the correct length (#5901). +* `geom_hline()` and `geom_vline()` now have `position` argument + (@yutannihilation, #4285). # ggplot2 3.5.1