R/visualisation_recipe.easycorrelation.R

Defines functions visualisation_recipe.easycorrelation

Documented in visualisation_recipe.easycorrelation

#' @rdname visualisation_recipe.easycormatrix
#'
#' @examples
#' \donttest{
#' # ==============================================
#' # Correlation Results (easycorrelation)
#' # ==============================================
#' if (require("see") && require("tidygraph") && require("ggraph")) {
#'   rez <- correlation(iris)
#'
#'   layers <- visualisation_recipe(rez)
#'   layers
#'   plot(layers)
#' }
#' }
#' @export
visualisation_recipe.easycorrelation <- function(x, ...) {
  insight::check_if_installed("tidygraph")

  x$width <- abs(x$r)
  data <- tidygraph::as_tbl_graph(x)

  # Initialize layers list
  layers <- list()

  layers[["l1"]] <- list(
    geom = "ggraph::geom_edge_arc",
    strength = 0.1,
    aes = list(edge_colour = "r", edge_width = "width")
  )
  layers[["l2"]] <- list(geom = "ggraph::geom_node_point", size = 22)
  layers[["l3"]] <- list(
    geom = "ggraph::geom_node_text",
    aes = list(label = "name"), colour = "white"
  )
  layers[["l4"]] <- list(geom = "ggraph::theme_graph", base_family = "sans")
  layers[["l5"]] <- list(geom = "guides", edge_width = "none")

  # Out
  class(layers) <- c("visualisation_recipe", "see_visualisation_recipe", class(layers))
  attr(layers, "data") <- data
  attr(layers, "layout") <- "kk"
  attr(layers, "ggraph") <- TRUE
  layers
}

Try the correlation package in your browser

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

correlation documentation built on April 6, 2023, 5:18 p.m.