From 42bf539c79a455cc0befb28561bc7aacbf31bb72 Mon Sep 17 00:00:00 2001 From: Immanuel Abdi Date: Tue, 26 Nov 2024 07:03:17 +0000 Subject: [PATCH] change plotting to work with ggplot2 >=v3.5 --- R/VisualizeData.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/VisualizeData.R b/R/VisualizeData.R index d84d63c6..6b2a5222 100644 --- a/R/VisualizeData.R +++ b/R/VisualizeData.R @@ -883,7 +883,11 @@ plotGroups <- function( #adapted from https://github.com/jwdink/egg/blob/master/R/set_panel_size.r g <- ggplotGrob(p) - legend <- grep("guide-box", g$layout$name) + legend_indices <- grep("guide-box", g$layout$name) + # ggplot versions > 3.5 can have multiple guide boxes, and are non automatically removed if is a "zeroGrob" + # Do filtering wrt only non "zeroGrob" legends + legend <- legend_indices[sapply(legend_indices, function(idx) class(g$grobs[[idx]])[1] != "zeroGrob")] + # add correct ones to legend if(length(legend)!=0){ gl <- g$grobs[[legend]] g <- ggplotGrob(p + theme(legend.position = "none"))