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

strata label positions #27

Closed
Tomasz-Olczyk opened this issue Dec 27, 2018 · 3 comments
Closed

strata label positions #27

Tomasz-Olczyk opened this issue Dec 27, 2018 · 3 comments

Comments

@Tomasz-Olczyk
Copy link

Description of the issue

After subsetting text labels of the strata in order to lessen the number of labels they are changing positions.

Reproducible example (preferably using reprex::reprex())

ggplot(data = titanic_wide,
aes(axis1 = Class, axis2 = Sex, axis3 = Age,
y = Freq)) +
scale_x_discrete(limits = c("Class", "Sex", "Age"), expand = c(.1, .05)) +
xlab("Demographic") +
geom_alluvium(aes(fill = Survived)) +
geom_stratum() + geom_text(data = subset(titanic_wide, Freq > 200), stat = "stratum", label.strata = TRUE) +
theme_minimal() +
ggtitle("passengers on the maiden voyage of the Titanic",
"stratified by demographics and survival")

image

@corybrunson
Copy link
Owner

The root problem here is that the stat_*() functions use aggregative functions, namely cumsum(), to convert frequency or count data into alluvium and stratum positions. This means that subsetting the data produces not a diagram with some elements removed and the others in their original positions, but an entirely different diagram. When this is only applied to one layer (in this case, the text labels), then that layer doesn't align with the other layers.

At present, i think the only way to do what you're after is to manipulate the data frame itself to create a new column of labels, some of which are blank...and this would only work for data in long format. But it seems like a general enough need to make it a feature. I'll try to get to this within the next couple of weeks.

Thanks for pointing this out!

@Tomasz-Olczyk
Copy link
Author

Thank you for fast replay and this great package. I'll try this solution.

@corybrunson
Copy link
Owner

v0.9.2 introduces the stat_stratum() parameters min.height and max.height that allow the user to restrict which strata (or, if used with geom_text(), which labels) to render. See the vignette on labeling small strata for an example. Thanks for the prompt!

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

No branches or pull requests

2 participants