I'm animating a map of NY fire calls last Thanksgiving using gganimate. My data is here; it has type of call, location of call, time the call was put in, and time the call was resolved. (I convert the latter two to POSIXct variables.) I'd like a map of NY animated to show, each minute, where fire calls have been put in but are not yet resolved.
I pull the NY map easily:
# Import map of NY
r <- GET('http://data.beta.nyc//dataset/0ff93d2d-90ba-457c-9f7e-39e47bf2ac5f/resource/35dd04fb-81b3-479b-a074-a27a37888ce7/download/d085e2f8d0b54d4590b1e7d1f35594c1pediacitiesnycneighborhoods.geojson')
nyc_neighborhoods <- readOGR(content(r,'text'), 'OGRGeoJSON', verbose = F)
nyc_neighborhoods_df <- tidy(nyc_neighborhoods)
Then I try to make the animated graph using transition_events:
# Make map
anim = ggplot() +
theme_bw() +
labs(title = "{round(frame_time)}", x = "", y = "", col = "") +
theme(panel.border = element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks.x=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
geom_polygon(data=nyc_neighborhoods_df, aes(x=long, y=lat, group=group)) +
geom_point(data=thanksgiving_day, aes(x=Longitude, y=Latitude, col=type)) +
transition_events(start = time_start, end = time_end)
But I get the following error:
Error in if (enter_length$class == "difftime" || enter_length$class == :
missing value where TRUE/FALSE needed
I get (different) errors even if I set enter_length and exit_length, unless I set them to POSIXct variables; but I'm not sure how to set a POSIXct variable to stand in for a length of time. Really I don't need any entering or exiting animation time at all; I'm not sure why these are apparently necessary.
Any thoughts?