Skip to content

Commit

Permalink
Merge pull request #2236 from GreenleafLab/ia/fix-ggplot-legends
Browse files Browse the repository at this point in the history
change plotting to work with ggplot2 >=v3.5
  • Loading branch information
immanuelazn authored Nov 26, 2024
2 parents 65968a4 + 42bf539 commit 474a057
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/VisualizeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 474a057

Please sign in to comment.