From bfc804683a542700172ed16a9ec9b1f61b8ffa02 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 18 Jan 2024 15:58:17 +0100 Subject: [PATCH] update `get_legend_title()` helper --- tests/testthat/helper.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index f8ccd161..3ea11c57 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -207,6 +207,11 @@ get_legend_title <- function(gg) { ggb <- ggplot2::ggplot_build(gg) ggt <- ggplot2::ggplot_gtable(ggb) + if (inherits(ggb$plot$guides, "Guides")) { + params <- ggb$plot$guides$get_params(1) + return(params$title) + } + legend_grob_id <- which(sapply(ggt$grobs, function(x) x$name) == "guide-box") legend_grob <- ggt$grobs[[legend_grob_id]]