Skip to content

Commit

Permalink
Merge pull request #80 from teunbrand/ggplot2_3.5.0
Browse files Browse the repository at this point in the history
Update `love.plot` to be compatible with upcoming ggplot2 version
  • Loading branch information
ngreifer committed Jan 16, 2024
2 parents f6da439 + 69f6530 commit b082657
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/love.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,14 @@ love.plot <- function(x, stats, abs, agg.fun = NULL,
else legend.to.get <- 1

legg <- ggplot2::ggplotGrob(plots.to.combine[[legend.to.get]] + ggplot2::theme(legend.position = position))
leg <- legg$grobs[[which(legg$layout$name == "guide-box")]]
if (any(legg$layout$name == "guide-box")) {
leg <- legg$grobs[[which(legg$layout$name == "guide-box")]]
} else if (any(legg$layout$name == paste0("guide-box-", position))) {
# ggplot2 >=3.5.0 can have multiple legends
leg <- legg$grobs[[which(legg$layout$name == paste0("guide-box-", position))]]
} else {
position <- "none"
}

if (position == "left") {
p <- gridExtra::arrangeGrob(grobs = list(leg, g), nrow = 1,
Expand Down

0 comments on commit b082657

Please sign in to comment.