R/ggsave.R

Defines functions ggsave

Documented in ggsave

# Wrapper function for ggsave
# Autor: Samuel Meier
# Datum: 04.03.2

# Packages ------------------------------------


library(ggplot2)

# Beispieldaten laden -----------------------------


# Wrapper for ggsave ---------

#' Wrapper for ggsave
#'
#' This function wraps around the ggsave function of gglpot2 (\link[ggplot2]{ggsave}) by setting the defaults to the SGB standard output.
#'
#' @param filename see documentation of \link[ggplot2]{ggsave}
#' @param wide boolean (default = FALSE), if TRUE widens the plot to width = 6.5 and height = 4.5
#' @param plot see documentation of \link[ggplot2]{ggsave}
#' @param device see documentation of \link[ggplot2]{ggsave}
#' @param path see documentation of \link[ggplot2]{ggsave}
#' @param scale see documentation of \link[ggplot2]{ggsave}
#' @param width see documentation of \link[ggplot2]{ggsave}
#' @param height see documentation of \link[ggplot2]{ggsave}
#' @param units see documentation of \link[ggplot2]{ggsave}
#' @param dpi see documentation of \link[ggplot2]{ggsave}
#' @param limitsize see documentation of \link[ggplot2]{ggsave}
#' @param ... see documentation of \link[ggplot2]{ggsave}
#'
#' @return see documentation of \link[ggplot2]{ggsave}
#' @export
#'
#' @examples
#' ggsave("my_sgb_plot.png")
ggsave <- function(filename,
                   wide = FALSE,
                   plot = last_plot(),
                   device = NULL,
                   path = NULL,
                   scale = 1,
                   width = 3.5,
                   height = 2.5,
                   units = "in",
                   dpi = 600,
                   limitsize = TRUE,
                   ...) {

  if (wide) {
    width <- 6.5
    height <- 4.5
  }
  ggplot2::ggsave(filename = filename,
                  plot = plot,
                  device = device,
                  path = path,
                  scale = scale,
                  width = width,
                  height = height,
                  units = units,
                  dpi = dpi,
                  limitsize = limitsize,
                  ... = ...)
}
SchweizerischerGewerkschaftsbund/gsgb documentation built on Dec. 18, 2021, 1 p.m.