R/new-plot.R

Defines functions new_plot.default new_plot.formula new_plot.grob new_plot.ggplot new_plot

Documented in new_plot new_plot.default new_plot.formula new_plot.ggplot new_plot.grob

#' Init a Annotation Plot
#' @description This function, similar to new_ggplot, is used to initialize an
#' annotated graph.
#' @param plot can be a ggplot, grob or base plot object.
#' @param ... other parameters.
#' @return a modified gg object.
#' @importFrom ggplotify as.ggplot
#' @rdname new_plot
#' @export
new_plot <- function(plot, ...) {
  UseMethod("new_plot")
}

#' @rdname new_plot
#' @method new_plot ggplot
#' @export
new_plot.ggplot <- function(plot, ...) {
  new_ggplot(plot = plot, ...)
}

#' @rdname new_plot
#' @method new_plot grob
#' @export
new_plot.grob <- function(plot, ...) {
  plot <- ggplotify::as.ggplot(plot)
  new_ggplot(plot = plot, ...)
}

#' @rdname new_plot
#' @method new_plot formula
#' @export
new_plot.formula <- function(plot, ...) {
  plot <- ggplotify::as.ggplot(plot)
  new_ggplot(plot = plot, ...)
}

#' @rdname new_plot
#' @method new_plot default
#' @export
new_plot.default <- function(plot, ...) {
  plot <- ggplotify::as.ggplot(plot)
  new_ggplot(plot = plot, ...)
}
Hy4m/newplot documentation built on Dec. 17, 2021, 11:24 p.m.