I'm trying to show the growth of COVID cases in New York state
This code gets the plot I want but without the animation or aspect of time.
Full error:
Error in insert_points(polygon$x, polygon$y, splits, n):
Not compatible with requested type: [type=NULL; target=double].
library(ggplot2)
library(gganimate)
library(transformer)
library(tidyverse)
county_map = map_data("county", region = "New York")
county_map$region = county_map$subregion
covidCounties = read.csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv", header = T)
covidCounties = covidCounties %>%
mutate(date = as.Date(date)) %>%
filter(state == "New York") %>%
arrange(date)%>%
group_by(county) %>%
mutate(county = tolower(county)) %>%
mutate(newCases = diff(c(0, cases))) %>%
mutate(newDeaths = diff(c(0, deaths))) %>%
ungroup() %>%
select(date, state, county, cases, newCases, deaths)
covidCountyMap = covidCounties %>%
ggplot(aes(
map_id = county,
fill = newCases,
group = county
))+
geom_map(
map = county_map,
color = "black"
)+
expand_limits(x = county_map$long, y = county_map$lat)+
scale_fill_gradientn(colors = c("green", "yellow", "red"), breaks = c(0, 100, 500))+
labs(
title = "New cases over time in New York State",
subtitle = "{frame_time}"
)
covidCountyMap
covidCountyMap+
transition_time(date)