From 9fe3cc155fc35cd19d348712172a1eae8e2c81b5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 31 Jan 2025 16:06:38 +0100 Subject: [PATCH] Allow to add global aes when plotting `visualisation_recipe()` (#383) * Allow to add global aes when plotting `visualosation_recipe()` * version --- DESCRIPTION | 2 +- R/plot.visualisation_recipe.R | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8931e8c4d..efb7fc3a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: see Title: Model Visualisation Toolbox for 'easystats' and 'ggplot2' -Version: 0.10.0 +Version: 0.10.0.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/plot.visualisation_recipe.R b/R/plot.visualisation_recipe.R index dd8e81ea6..7b3f701bf 100644 --- a/R/plot.visualisation_recipe.R +++ b/R/plot.visualisation_recipe.R @@ -7,8 +7,16 @@ plot.see_visualisation_recipe <- function(x, ...) { } 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, ...)) + global_aes <- attributes(x)$global_aes + if (!is.null(global_aes) && length(global_aes)) { + global_aes <- do.call(ggplot2::aes, args = lapply(global_aes, .str_to_sym)) + } + suppressWarnings( + do.call( + ggplot2::ggplot, + insight::compact_list(list(data = attributes(x)$data, mapping = global_aes)) + ) + geoms_from_list(x, ...) + ) } }