I am using the wonderful gratia package to visualize multiple gam models from the mgcv package using the compare_smooths function. While I am able to create the gams properly and draw them, I cannot find a way to force the legend to the bottom of the figure.
My code is the following:
library(tidyverse)library(gratia)library(mgcv)library(ggpubr)gam1 <- gam(mpg ~ am + s(hp),data = mtcars |> filter(cyl >= 6))gam2 <- gam(mpg ~ am + s(hp),data = mtcars |> filter(cyl < 6))gam3 <- gam(mpg ~ am + s(hp),data = mtcars |> filter(qsec >= 18))gam4 <- gam(mpg ~ am + s(hp),data = mtcars |> filter(qsec < 18))plot1 <- draw(compare_smooths(gam1,gam2)) + theme(legend.position = "bottom")plot2 <- draw(compare_smooths(gam3,gam4)) + theme(legend.position = "bottom")gamplot <- ggarrange(plotlist = list(plot1,plot2),ncol = 2) gamplotWhich creates the following result:
This doesn't have the legend at the bottom, despite specifying it to be so. I also tried using the legend position from ggarrange but that didn't work either:
gamplot2 <- ggarrange(plotlist = list(plot1,plot2),ncol = 2,legend = "bottom") gamplot2And even when the sets are by themeselves, this does not help:
plot1I would like to put both the legends at the bottom. How can I do this? Is this possible within gratia using compare_smooths, or is this not doable?


