Skip to content

Commit

Permalink
update get_legend_title() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 18, 2024
1 parent a402e0d commit bfc8046
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down

0 comments on commit bfc8046

Please sign in to comment.