gratia icon indicating copy to clipboard operation
gratia copied to clipboard

The ordering of plots in draw.gam doesn't always match the order in which the smooths entered the model

Open gavinsimpson opened this issue 4 years ago • 1 comments

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.

gavinsimpson avatar Mar 18 '22 07:03 gavinsimpson

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

swer-draw-output

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!

gavinsimpson avatar Mar 18 '22 09:03 gavinsimpson