Reputation: 221
I'm trying to animate points moving over a map in gganimate. In teh following example, animating just the points works and a static plot of the points and map works, but combining them fails with the error Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length
Here's a repro:
# gganimate isn't on CRAN
devtools::install_github('thomasp85/gganimate')
library(tidyverse)
library(gganimate)
library(sf)
# for the spatial data
library(rnaturalearth)
# Points data
time <- seq(ISOdate(2015, 6, 1), ISOdate(2015, 8, 1), length.out = 100)
track1 <- tibble(lon = seq(-161, -155, length.out = 100),
lat = seq(19, 25, length.out = 100),
time = time,
trackid = 1)
track2 <- tibble(lon = seq(-155, -161, length.out = 100),
lat = seq(19, 25, length.out = 100),
time = time,
trackid = 2)
d <- rbind(track1, track2)
# Spatial data
earth <- st_as_sf(ne_download(scale = "medium",
category = "physical",
type = "coastline"))
deg_buff <- 1
lon_range <- range(d$lon) + c(-deg_buff, deg_buff)
lat_range <- range(d$lat) + c(-deg_buff, deg_buff)
bbox <- st_polygon(list(cbind(lon_range[c(1,1,2,2,1)],
lat_range[c(1,2,2,1,1)])))
bbox <- st_sfc(bbox)
st_crs(bbox) <- st_crs(earth)
area <- st_intersection(earth, bbox)
p <- ggplot(d, aes(lon, lat)) +
geom_point() +
labs(subtitle = 'Date: {format(frame_time, "%b %e")}') +
transition_components(trackid, time) +
shadow_trail(distance = 0.01, size = 0.3)
animate(p, 100, 20)
ggplot(d, aes(lon, lat)) +
geom_sf(data = area, inherit.aes = FALSE) +
geom_point()
p2 <- ggplot(d, aes(lon, lat)) +
geom_sf(data = area, inherit.aes = FALSE) +
geom_point() +
labs(subtitle = 'Date: {format(frame_time, "%b %e")}') +
transition_components(trackid, time) +
shadow_trail(distance = 0.01, size = 0.3)
animate(p2, 100, 20)
Upvotes: 0
Views: 1649
Reputation: 4989
data = d
and aes()
from ggplot()
to geom_point()
transition_components()
to transition_time()
shadow_trail
to shadow_wake
p2 <- ggplot() +
geom_sf(data = area, color = "red") +
geom_point(data = d, aes(lon, lat), inherit.aes = FALSE) +
labs(subtitle = 'Date: {format(frame_time, "%b %e")}') +
transition_time(time) +
shadow_wake(0.3)
animate(p2, 100)
Upvotes: 2
Reputation: 670
trackid is undefined and what throws the error in p2; time is defined.
Upvotes: 0