As the number of cases of COVID-19 infections continues to climb throughout the United States, many of us are following closely the daily statistics for counties of particular significance to us personally. The New York Times has provided a public github repository of the daily data that can easily be extracted for selected counties.

The New York Times has made publicly available an ongoing repository of data on coronavirus cases and deaths in the U.S. We can read the relevant CSV files directly using dplyr:

# Pull data from NYT's repository

state_data <- read_csv('https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv')
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   state = col_character(),
##   fips = col_character(),
##   cases = col_double(),
##   deaths = col_double()
## )
county_data <- read_csv('https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv')
## Parsed with column specification:
## cols(
##   date = col_date(format = ""),
##   county = col_character(),
##   state = col_character(),
##   fips = col_character(),
##   cases = col_double(),
##   deaths = col_double()
## )

Below you can modify this list of counties (and corresponding states) that are of interest to you.

# Select counties of interest 

home_counties <- tribble( ~county, ~state,
                          "King", "Washington",
                          "Santa Clara", "California",
                          "San Bernardino", "California",
                          "Westchester", "New York",
                          "Middlesex", "New Jersey" )
                          
home_counties <- home_counties %>% mutate(state_label = str_glue("{county} ({state})"))

Final Plot

Finally, we plot the reported cases in the counties of interest.

# Filter data to selected counties by performing join
home_data <- home_counties %>% inner_join(county_data)
## Joining, by = c("county", "state")
# Identify latest data value for labels
last_point <- home_data %>% filter(date == max(date))

g <- home_data %>% 
  ggplot( aes(x = date, y = cases) ) + 
  geom_line(aes(color = state_label), na.rm = TRUE) +
  labs(title = "Reported cases of COVID-19",
       subtitle = "Selected counties",
       caption = 'Source: The New York Times, https://github.com/nytimes/covid-19-data',
       x = "") +
  scale_y_continuous(label = comma) +
  geom_text_repel(data = last_point,
            aes(x = date, y = cases, color = state_label,
                label = comma_format(accuracy = 1)(cases)),
            size = 3,
            fontface = "bold",
            hjust = 1,
            vjust = 0.5,
            show.legend = F) +
  theme_hc() +
    theme(legend.title = element_blank(),
          legend.position = c(0.2, 0.7))
g