gavinsimpson / gratia

ggplot-based graphics and useful functions for GAMs fitted using the mgcv package
https://gavinsimpson.github.io/gratia/
Other
206 stars 28 forks source link

When plotting 3-d and 4-d smooths choose to plot 2d smooth as the surface #191

Closed gavinsimpson closed 1 year ago

gavinsimpson commented 2 years ago

When plotting 3d and 4d smooths, we could do better than currently by being a bit selective about what we plot on the surface with geom_raster() and what we assign to the facets.

With a smooth like te(year, long, lat, d = c(1, 2), bs = c("cr", "tp")) say, currently we would plot lat on the facets as it is the third covariate we identify in the smooth definition. instead, we could identify that there is a natural decomposition of this smooth into a series of spatial surfaces, and we should identify if there is a multi-d marginal smooth and if so select the covariates for the other marginal smooth(s) to be the facetting variables.

See the Galveston Bay example for a specific example.

Note that if that example uses bam(..., discrete = TRUE) then the ti() terms will get reordered (as per ?bam) and this makes it impossible to rearrange the order of covariates to "trick" draw() into drawing the right variable(s) as facets. Hence we need to fix finding the 2d smooth.