1

This is a plot that I'm trying to create like the one that was shown in nytimes.

My code:

ggplot(gwsj, aes(x = Year, y = Freq, color = Gender)) + 
  geom_line(size = 1.2, aes(alpha = Functn)) + 
  geom_point(aes(alpha = Functn)) + 
  scale_color_manual(values = c("Female" = "#d81b60", "Male" = "#1976d2")) +
  facet_wrap(~OrgType, scales = "free_y") +
  theme_pubclean()

What I get:

enter image description here

What I want

The scale that shows the gender count and the Functn legend with colors and opacity like the ones shown in nytimes. I've tried many things, but I'm missing something somewhere

user1828605
  • 1,723
  • 1
  • 24
  • 63
  • It doesn't seem like the nytimes plot encodes anything in the opacity, and I don't exactly get why you are encoding a categorical variable as opacity. Would you explain what exactly you think is wrong with your current approach? – teunbrand Apr 01 '20 at 13:26
  • It's not that it's wrong, just wanted to identify which `Functn` is which. Right now, this plots only shows the `gender` and the opacity would be the `Functn`. What I really want is the distribution of the gender across Functn. I hope this is clear – user1828605 Apr 01 '20 at 13:31
  • As far as I get it, the nytimes plot simply maps the share of females/males, i.e. a continous variable, for different occupations on color which automatically results in the kind of gradient color scale. However, which occupation (which as I got it correpsonds to your `Functn`) corresponds to which line is not visible from the plot. That's why they added the annotations for some example occupations. – stefan Apr 01 '20 at 13:56
  • 1
    I think the nytimes plot is very convoluted and I don't know if I would try to reproduce it. ... FYI, They have a "discrete continuous scale", which is *not* an inbuilt feature of ggplot. [But there is a solution for this, see this thread](https://stackoverflow.com/questions/50506832/create-discrete-color-bar-with-varying-interval-widths-and-no-spacing-between-le/50518287#50518287) – tjebo Apr 01 '20 at 14:35

0 Answers0