Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting sz factor smooth deviations separately #244

Open
joepiekos opened this issue Dec 12, 2023 · 2 comments
Open

Plotting sz factor smooth deviations separately #244

joepiekos opened this issue Dec 12, 2023 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@joepiekos
Copy link

when using draw.smooth_estimates() on a GAM with sz smooths, it currently generates one plot per factor with the deviation smooths for each level layered on top of each other. As I understand it this allows for a quicker visual comparison between factor levels, however with any more than realistically 3 smooths the plot becomes quite hard to interpret. For example:

image

In my own fork of gratia I can separate these plots, by essentially just adding a return(sm_l) in the draw.smooth_estimates() function, and then using that returned dataframe to manually plot the smooths (using the ggplot in plot_smooth.sz_factor_smooth() with an added facet_wrap into that ggplot)

Is there any way this could be added? Not sure exactly what form it would take, or if you think it is a good idea? It is just slightly nicer to see the deviations separately, even though the main event is the final "combined" smooth where you combine the deviations so to speak (I can do this fine note).

Many thanks for all your work! Let me know if I can clarify anything

@gavinsimpson gavinsimpson added the enhancement New feature or request label Dec 12, 2023
@gavinsimpson
Copy link
Owner

This is a little more complicated to do automagically; "sz" and "fs" smooths are stored as a single smooth in the model, whereas factor by smooths are considered as entirely separate smooths and stored separately. When draw.gam() works on the smooths, it operates at this level of smooth, and expects 1 plot per element in the $smooth component of the fitted model. There's nothing stopping me returning multiple ggplot objects from the plot_smooth() methods. What is a problem is getting draw.gam() to unwrap these objects into the list of plots. I'll have to look at ways of unnesting a list but only if an element of that list contains multiple ggplot objects.

Let me see what I can do...

@gavinsimpson
Copy link
Owner

Something like this

renquote <- function(l) if (is.list(l)) lapply(l, renquote) else enquote(l)

lapply(unlist(renquote(ml)), eval)

from https://stackoverflow.com/a/19737149/429846 seems like it will flatten a list of the form needed here.

@gavinsimpson gavinsimpson added this to the 0.10 milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants