-
Notifications
You must be signed in to change notification settings - Fork 34
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
strata ordering fails to respect factor levels #13
Comments
The problem is that some strata are used at multiple axes. Inside In the meantime, @svenhalvorson, you can dodge the problem either (a) by slightly changing the names of the strata at one axis:
or (b) by assigning the same, larger set of levels to both axes:
|
Current plan for
|
An attempt to resolve this issue is at the order branch. It adds a parameter I'm not especially fond of this patch, since it requires passing (yet another) cumbersome parameter to every ggalluvial layer. But the problem is likely to be rare enough that it shouldn't be a problem (and it can be easily programmed). Feedback would be very welcome! |
Thank you corybrunson! I've got some beautiful graphs out of this package! |
@svenhalvorson , that's great to know! Thank you for saying so. : ) Have you tried the
Anything more creative than that, and it's probably better for the user to handle it manually (as in the solution posted on SO). Does that sound reasonable? |
Hi @corybrunson , trying to accomplish something similar, but following along with the solutions and converting to lodes form I get errors that it isn't a recognized alluvial form, despite library(ggalluvial)
a <- data.frame(
"Older structure" = c(
"Class",
"Neighborhood",
"Neighborhood",
"Subclass",
"Cluster",
"None"
),
"Current structure" = c(
"Neurotransmitter type",
"Neighborhood",
"Class",
"Subclass",
"Supertype",
"Cluster"
),
N = rep(1, 6)
)
a$Older.structure <- factor(a$Older.structure, levels = unique(a$Older.structure))
a$Current.structure <- factor(a$Current.structure, levels = a$Current.structure)
ggplot(data = a, aes(axis1 = Older.structure, axis2 = Current.structure, y = N)) +
geom_alluvium() +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Older structure", "Current structure")) +
theme_classic() +
ggtitle("Naming structure changes",
"Yao et al 2021 --> Yao et al 2023") Produces plot with second axis strata out of order: Trying to lodes form can't get past checks b <- to_lodes_form(a[1:2])
is_lodes_form(b, key = x, value = stratum, id = alluvium, silent = TRUE)
# [1] TRUE
ggplot(data = b, aes(x = x, stratum = stratum, alluvium = alluvium)) +
geom_alluvium() +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Older structure", "Current structure")) +
theme_classic() +
ggtitle("Naming structure changes",
"Yao et al 2021 --> Yao et al 2023")
Error in `geom_alluvium()`:
! Problem while computing stat.
ℹ Error occurred in the 1st layer.
Caused by error in `setup_data()`:
! Data is not in a recognized alluvial form (see `help('alluvial-data')` for details).
Run `rlang::last_trace()` to see where the error occurred. Trying in a form more like the stackoverflow version still errors at the same step b$N <- 1
ggplot(b, aes(x = x, stratum = stratum, alluvium = alluvium, weight = N, label = stratum)) +
geom_flow(aes(fill = stratum)) +
geom_stratum() +
geom_text(stat = "stratum") +
scale_x_discrete(limits = c("Older structure", "Current structure")) +
theme_classic() +
ggtitle("Naming structure changes",
"Yao et al 2021 --> Yao et al 2023") |
Hi @rbutleriii and i apologize for taking a while to respond—i've been traveling and distracted for several weeks. I think what you need to do here is define both variables as factors with the same combined set of levels—and with the levels in the desired order. Could you give that a try and report back? If that's not clear then let me know and i'll do an illustration using your data within a few days. |
Originally raised in a comment on #6 . See example here.
The text was updated successfully, but these errors were encountered: