0
weekend_trips %>%
  group_by(hour_of_day, member_casual, month) %>%
  summarise(number_of_rides = n()/2) %>%
  mutate(month = factor(month.name[as.numeric(month)]), levels = month.name) %>%
  ggplot(aes(x = hour_of_day, y = number_of_rides, fill = member_casual)) + 
  geom_col(position = "dodge") +
  facet_wrap(~month)

This code gives me this: Graphs in alphabetical order

If I don't cast month as.numberic, month becomes NA.

Edit: I figured it out.

weekend_trips$month <- month.name[as.numeric(weekend_trips$month)]

weekend_trips %>%
  group_by(hour_of_day, member_casual, month) %>%
  summarise(number_of_rides = n()/2) %>%
  mutate(month = factor(month, levels = month.name)) %>%
  ggplot(aes(x = hour_of_day, y = number_of_rides, fill = member_casual)) + 
  geom_col(position = "dodge") +
  facet_wrap (~month)

I would appreciate someone telling me why I couldn't burden mutate() so much.

0 Answers0