Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. library(dslabs)
  2. library(tidyverse)
  3. data(us_contagious_diseases)
  4. the_disease <- "Measles"
  5. min_weeks_reporting <- 10
  6. dat <- us_contagious_diseases %>%
  7. filter(
  8. disease == the_disease &
  9. weeks_reporting >= min_weeks_reporting &
  10. !is.na(population)
  11. ) %>%
  12. mutate(rate = count / population * 10000 * 52 / weeks_reporting)
  13. dat %>% ggplot(aes(year, state, fill = rate)) +
  14. geom_tile(color="grey40")+
  15. scale_x_continuous(expand=c(0,0)) +
  16. scale_fill_gradientn(colors = RColorBrewer::brewer.pal(9, "Reds"), trans = "sqrt") +
  17. geom_vline(xintercept=1963, col = "blue") +
  18. theme_minimal() +
  19. theme(panel.grid = element_blank()) +
  20. ggtitle(the_disease) +
  21. ylab("") +
  22. xlab("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement