R/plot.visualisation_recipe.R

Defines functions plot.see_visualisation_recipes plot.see_visualisation_recipe

#' @export
plot.see_visualisation_recipe <- function(x, ...) {
  if ("ggraph" %in% names(attributes(x))) {
    insight::check_if_installed("ggraph")
    if (!"ggraph" %in% .packages()) {
      attachNamespace("ggraph") # Needs to be attached
    }
    suppressWarnings(ggraph::ggraph(attributes(x)$data, layout = attributes(x)$layout) + geoms_from_list(x))
  } else {
    suppressWarnings(ggplot2::ggplot(data = attributes(x)$data) +
      geoms_from_list(x, ...))
  }
}

# Example
# vr1 <- datawizard::visualisation_recipe(correlation::correlation(iris))
# vr2 <- datawizard::visualisation_recipe(summary(correlation::correlation(iris)))
# x <- list(p1 = vr1, p2 = vr2)
# class(x) <- "see_visualisation_recipes"
# plot(x)
#' @export
plot.see_visualisation_recipes <- function(x, ...) {
  the_plots <- list()
  for (i in names(x)) {
    the_plots[[i]] <- suppressWarnings(graphics::plot(x[[i]]))
  }
  pw <- plots(the_plots, ...)
  .safe_print_plots(pw)
  invisible(pw)
}

Try the see package in your browser

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

see documentation built on Nov. 3, 2023, 5:10 p.m.