Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22514

Cannot force legend to bottom in gratia::compare_smooths

$
0
0

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) gamplot

Which creates the following result:

plot1

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") gamplot2

plot2

And even when the sets are by themeselves, this does not help:

plot1

plot3

I 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?


Viewing all articles
Browse latest Browse all 22514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>