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

how to use colors and linetypes selectively in geom_bump #17

Open
friendly opened this issue Nov 27, 2021 · 0 comments
Open

how to use colors and linetypes selectively in geom_bump #17

friendly opened this issue Nov 27, 2021 · 0 comments

Comments

@friendly
Copy link

I'm trying to do a ggbump chart where there are too many categories of the rank variable to depend on color alone.
See: https://twitter.com/datavisFriendly/status/1464431392499109892 for what I'm working on.

At the minimum, I'd like to also vary linetype, and/or use colors selectively, so most are black, but a few are distinguished by color. I can't see any way to pass appropriate arguments to geom_bump()

Here is my code:

ggplot(data = propens,
       aes(x=age, y=rank, color = crime)) +
#  scale_y_continuous(breaks = 1:10) +
  geom_point(size = 4) +
  geom_bump(size = 1.5, 
#            linetype = rep(c("solid", "longdash"),length=5500)
            ) +
  geom_label(aes(label=share), size=4) +
  geom_text(data = propens %>% 
              filter(age == ">70") %>% 
              mutate(age = 7),
            aes(x = age + .3, label = crime_label), 
            size = 4, hjust = 0, lineheight=0.7) +
  geom_text(data = propens %>% 
              filter(age == "<21") %>% 
              mutate(age = 1),
            aes(x = age - .3, label = crime_label), 
            size = 4, hjust = 1, lineheight=0.75) +
  scale_x_discrete(expand=c(0.3, 0.25)) +
  scale_y_reverse() +
  theme_minimal_grid() +
  theme(legend.position = "none",
        panel.grid.major = element_blank()) +
  labs(title = 'Distribution of crimes at different ages in periods of ten years') +
  labs(y = "Rank",
       x = "Age group") 
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

1 participant