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

geom_flow does not work properly with ggnewscale #120

Open
mdhall272 opened this issue Sep 13, 2023 · 1 comment
Open

geom_flow does not work properly with ggnewscale #120

mdhall272 opened this issue Sep 13, 2023 · 1 comment

Comments

@mdhall272
Copy link

mdhall272 commented Sep 13, 2023

Description of the issue

If you try to use ggnewscale to have different fills for flows and strata, then one of them will not show up. (This does not seem to happen with geom_alluvium, only geom_flow.)

Reproducible example

Adapted from https://www.r-bloggers.com/2022/10/how-to-create-a-ggalluvial-plot-in-r/:

ggplot(data = vaccinations,
       aes(axis1 = survey, axis2 = response, y = freq)) +
  geom_flow(aes(fill = response)) +
  scale_fill_brewer(palette = "Set1") +
  geom_stratum(aes(fill = response)) +
  geom_text(stat = "stratum",
            aes(label = after_stat(stratum))) +
  scale_x_discrete(limits = c("Survey", "Response"),
                   expand = c(0.15, 0.05)) +
  theme_void()

But now suppose we want to use ggnewscale to use different fill scales for the stratum and the flow:

library(ggnewscale)

ggplot(data = vaccinations,
       aes(axis1 = survey, axis2 = response, y = freq)) +
  geom_flow(aes(fill = response)) +
  scale_fill_brewer(palette = "Set1") +
  new_scale_fill()+
  geom_stratum(aes(fill = response)) +
  scale_fill_brewer(palette = "Set2") +
  geom_text(stat = "stratum",
            aes(label = after_stat(stratum))) +
  scale_x_discrete(limits = c("Survey", "Response"),
                   expand = c(0.15, 0.05)) +
  theme_void()

The flow fills do not show up. Alternatively, if you do this in the opposite order:

ggplot(data = vaccinations,
       aes(axis1 = survey, axis2 = response, y = freq)) +
  geom_stratum(aes(fill = response)) +
  scale_fill_brewer(palette = "Set2") +
  new_scale_fill()+
  geom_flow(aes(fill = response)) +
  scale_fill_brewer(palette = "Set1") +
  geom_text(stat = "stratum",
            aes(label = after_stat(stratum))) +
  scale_x_discrete(limits = c("Survey", "Response"),
                   expand = c(0.15, 0.05)) +
  theme_void()

The strata fills do not show up.

I'm aware that the bug could easily be in ggnewscale and this request may be a bit above and beyond the call of duty!

@corybrunson
Copy link
Owner

Hi @mdhall272, this is an interesting issue, thanks. I can reproduce the problem, and i see that it's not an issue of where data is specified (as i thought might be based on the {ggnewscale} examples). I'll have a closer look ASAP, but that might not be this or next week.

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