gratia
gratia copied to clipboard
The ordering of plots in draw.gam doesn't always match the order in which the smooths entered the model
I think something must be going on to reorder the smooth column somewhere in all the group_by, mapping, nesting/unnesting, binding, etc that happens in draw.gam()
An easy solution should be to use smooths() to reorder the column into the order that the smooths entered the model.
As an extreme example, see this for the Swiss extreme rainfall example data set used in the second edition of Simon Wood's book:
require("gamair")
library("gratia")
library("mgcv")
data(swer, package = "gamair")
m <- gam(list(exra ~ s(nao) + s(elevation) + climate.region + s(N, E),
~ s(year) + s(elevation) + climate.region + s(N, E),
~ climate.region),
family = gevlss(),
data = swer)
draw(m)
with the draw(m) resulting in

Where the smooths for the scale parameter of the GEV come before those for the location parameter, and are in the wrong order within those parameters!