# install.packages("dslabs")

library(dslabs)
library(tidyverse)
## -- Attaching packages ---------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2     v purrr   0.3.4
## v tibble  3.0.3     v dplyr   1.0.2
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(naniar)



measles <- us_contagious_diseases %>%

  filter(!state%in%c("Hawaii","Alaska") & disease == "Measles") %>%

  mutate(rate = count / population * 10000 * 52 / weeks_reporting) %>%
  
  mutate(count_new = replace(count, count >5000, 5000)) %>%
  filter(count_new >= 25)


measles2 <-us_contagious_diseases %>%

  filter(!state%in%c("Hawaii","Alaska") & disease == "Measles") %>%

  mutate(rate = count / population * 10000 * 52 / weeks_reporting)
view(measles)

###Attempt 1

ggplot(measles, aes(year,state)) +
  geom_point(aes(color=count_new)) +
  scale_color_distiller(palette = "RdYlGn", direction = -1)+
  geom_vline(xintercept = 1963)

  #scale_y_discrete(trans = "reverse")
ggplot(measles2, aes(year, count, group = state, color = state)) +
  geom_line() +
  geom_vline(xintercept = 1963) +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text = element_blank())