R/sgl_geom_bar.R

Defines functions ggplot_dir_from_qual.sgl_geom_bar has_direction.sgl_geom_bar valid_qual_list.sgl_geom_bar ggplot_aes.sgl_geom_bar valid_non_pos_aes.sgl_geom_bar ggplot_geom.sgl_geom_bar geom_name.sgl_geom_bar new_sgl_geom_bar

new_sgl_geom_bar <- function() {
  new_sgl_geom(class = "sgl_geom_bar")
}

#' @export
geom_name.sgl_geom_bar <- function(geom) {
  "bar"
}

#' @export
ggplot_geom.sgl_geom_bar <- function(geom) {
  ggplot2::geom_bar
}

#' @export
valid_non_pos_aes.sgl_geom_bar <- function(geom) {
  "color"
}

#' @export
ggplot_aes.sgl_geom_bar <- function(geom, layer, df, scales) {
  ggplot_aes_mapping <- NextMethod()
  if ("colour" %in% names(ggplot_aes_mapping)) {
    names(ggplot_aes_mapping)[names(ggplot_aes_mapping) == "colour"] <- "fill"
  }
  ggplot_aes_mapping
}

#' @export
valid_qual_list.sgl_geom_bar <- function(geom) {
  c(
    "horizontal",
    "unstacked",
    "vertical"
  )
}

#' @export
has_direction.sgl_geom_bar <- function(geom) {
  TRUE
}

#' @export
ggplot_dir_from_qual.sgl_geom_bar <- function(geom, qual) {
  if (qual == "vertical") {
    return("x")
  }
  "y"
}

Try the rsgl package in your browser

Any scripts or data that you put into this service are public.

rsgl documentation built on June 9, 2026, 1:07 a.m.