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

Computation failed in stat_stratum() with alluvial plots #108

Closed
hmlea opened this issue Feb 6, 2023 · 6 comments
Closed

Computation failed in stat_stratum() with alluvial plots #108

hmlea opened this issue Feb 6, 2023 · 6 comments

Comments

@hmlea
Copy link

hmlea commented Feb 6, 2023

When trying to make alluvial plots, I always get the following error:

1: Computation failed in `stat_stratum()`
Caused by error in `nth()`:
! unused argument (na_rm = na_rm)

The plot gets produces but without the labels. An example is with the UC Berkley admissions outlined in the help manual:

ggplot(as.data.frame(UCBAdmissions),
       aes(y = Freq, axis1 = Gender, axis2 = Dept)) +
    geom_alluvium(aes(fill = Admit), width = 1/12) +
    geom_stratum(width = 1/12, fill = "black", color = "grey") +
    geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
    scale_x_discrete(limits = c("Gender", "Dept"), expand = c(.05, .05)) +
    scale_fill_brewer(type = "qual", palette = "Set1") +
    ggtitle("UC Berkeley admissions and rejections, by sex and department")

The code gives the error and produces the following plot without the labels:
alluv

Is there something I am doing wrong or a way I can fix this?

@corybrunson
Copy link
Owner

Thanks @hmlea for raising the issue. This was an unintended consequence of making {ggalluvial} compatible with {dplyr} 1.1.0; see #107. It should be resolved once {dplyr} is upgraded. Please let me know if it is not!

Since it seems likely to cause confusion, i'll submit another patch ASAP with either a fix (if i can figure one out) or the current specification of dplyr >= 1.1.0 in the package description, which will alert users on installation to upgrade {dplyr}. This issue should remain open until then.

@hmlea
Copy link
Author

hmlea commented Feb 7, 2023

I appreciate the quick response. I was using dplyr 1.0.10 but updating to 1.1.0 fixed the issue.

@corybrunson
Copy link
Owner

OK, i better understand the problem: first() and last() are defined for {ggalluvial} when it is built on my own machine, and therefore depend on the version of {dplyr} i have installed. So, if i build the package with {dplyr} v1.1.0 installed, then you install it while you have {dplyr} v1.0.10 installed, then stat_*() will attempt to use the functions with syntax as in v1.1.0 but scaffolding as in v1.0.10. Since they both rely on nth(), any changes to that function's syntax throws an error. (The problem was reversed when users attempted to use the old {ggalluvial} built with an earlier {dplyr} after having installed the new {dplyr}.

The solution seems to be to call dplyr::first() and dplyr::last() from within {ggalluvial} functions, rather than importing them. I'll give that a whirl and, if it works, resubmit to CRAN.

@corybrunson
Copy link
Owner

@hmlea if and when you install version 0.12.5 from CRAN, could you confirm that the problem is still resolved?

@hmlea
Copy link
Author

hmlea commented Feb 22, 2023

Just tested the UC Berkley Admissions example in the vignette and it is working wit h dyplr 1.0.10 and 1.1.0. Thanks for the quick fix!

@corybrunson
Copy link
Owner

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants