Skip to content

expose stat argument in geom_vline and geom_hline? #6559

@EvaMaeRey

Description

@EvaMaeRey

I think it would be nice to expose the stat argument in geom_vline and geom_hline. These are rare exceptions where you aren't be able to access the Geom from the analogous user-facing function geom_*(), like geom_segment(stat = StatManual), geom_point(stat = StatNewCustom)...

The following modification might be in the right direction. The stat change does raise some more questions of exposing position, and other arguments additionally.

geom_vline <- function(mapping = NULL, data = NULL,
                       ...,
                       xintercept,
                       na.rm = FALSE,
                       show.legend = NA,
                       stat = "identity") {                   #<<<< new exposed argument

  # Act like an annotation
  if (!missing(xintercept)) {
    # Warn if supplied mapping and/or data is going to be overwritten
    if (!is.null(mapping)) {
      cli::cli_warn("{.fn geom_vline}: Ignoring {.arg mapping} because {.arg xintercept} was provided.")
    }
    if (!is.null(data)) {
      cli::cli_warn("{.fn geom_vline}: Ignoring {.arg data} because {.arg xintercept} was provided.")

  # add a warning about stat being ignored if xintercept is provided ?
  
    }

    data <- data_frame0(xintercept = xintercept)
    mapping <- aes(xintercept = xintercept)
    show.legend <- FALSE
  }

  layer(
    data = data,
    mapping = mapping,
    stat = stat,                   #<<<< not fixed
    geom = GeomVline,
    position = PositionIdentity,
    show.legend = show.legend,
    inherit.aes = missing(xintercept),       #<<<< This change or similar
    params = rlang::list2(
      na.rm = na.rm,
      ...
    )
  )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions