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

draw.gam() should set widths = 1 #190

Closed
gavinsimpson opened this issue Oct 12, 2022 · 3 comments
Closed

draw.gam() should set widths = 1 #190

gavinsimpson opened this issue Oct 12, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@gavinsimpson
Copy link
Owner

The default behaviour in patchwork when aligning patches of plots where one or more has a fixed/equal coordinate system is not desirable for draw.gam() and related plotting functions as it reduces the widths of the columns to align the axes. In these situations we don't want to align the axes as we are specifically trying to preserve the aspect ratio for select plots.

The fix in this situation seems to be to set the widths argument such that all patches are the same size. See https://patchwork.data-imaginist.com/articles/guides/layout.html#fixed-aspect-plots

@gavinsimpson gavinsimpson added the bug Something isn't working label Oct 12, 2022
@gavinsimpson gavinsimpson added this to the 0.8 milestone Oct 12, 2022
@Skogur
Copy link

Skogur commented Oct 25, 2022

I'm not sure if this is related or not, but will share in case it is helpful...

I have consistently been having issues when plotting factor-grouped* 2D smooths via gratia::draw(). I was (& remain) unsure of if this was on gratia's end or mine (perhaps multiple ggplot-related packages not playing nicely with one another?). However, after wrestling with this issue for some time, I recently discovered that simply adding + theme(aspect.ratio = 1) fixed the problem. Graphical output examples below.

Figured i should share in case it were related here or others are seeking solution for this as well....

### Before...

gam1 <- gam(y ~ factor1 + s(x1, x2, by = factor1), ...)  
draw(gam1, select = smooths(gam1)[2] ) 

image

### After...

  draw(gam1, select = smooths(gam1)[2] ) + 
      theme(aspect.ratio = 1)

image

PS major thanks for all that you do!

edit* : neglected to mention this was only an issue for 2D smooths grouped by factor (e.g., s(x1, x2, by = factor1))

@gavinsimpson
Copy link
Owner Author

@Skogur Looks like you shouldn't be using s() for this smooth as it assumes isotropy. Instead use te(x1, x2, by = f).

@Skogur
Copy link

Skogur commented Oct 26, 2022

Good catch! -___- this must be why taking breaks is important...

gavinsimpson added a commit that referenced this issue Nov 8, 2022
gavinsimpson added a commit that referenced this issue Nov 8, 2022
gavinsimpson added a commit that referenced this issue Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants