I am trying to animate two lists (one sfc_GEOMETRY of German federal states and the states which share borders with them, one sfc_POINT with all weather stations within the first) simultaneously, but have problems figuring out how either to combine these lists or to call the transition state in both lists. Does anyone of you know how to call them simultaneously? The repex does not make a lot of sense on this level, I am sorry for that. But, it does run faster that way.
Thanks a lot
library(raster)
library(sf)
library(rdwd)
library(ggplot2)
library(gganimate)
germany <- getData("GADM", country = "DEU", level=1)
germany.sf <- st_as_sf(germany)
geo.germany <- list()
for (i in 1:nrow(germany.sf)) {
geo.germany[[i]] = st_union(germany.sf[germany.sf[i, ], ])
}
geo.germany = do.call(c, geo.germany)
names <- germany.sf$NAME_1
data("metaIndex")
meta.stations <- metaIndex; rm(metaIndex)
meta.stations <- meta.stations[meta.stations$res=="daily" & meta.stations$var=="kl" & meta.stations$per=="recent" & meta.stations$hasfile, ]
stations.sf <- sf::st_as_sf(meta.stations, coords=c("geoLaenge", "geoBreite"), crs=4326)
int.stations <- sf::st_intersects(geo.germany, stations.sf)
stations <- list()
for (i in 1:length(names)) {
stations[i] = list(stations.sf[int.stations[[i]],]$geometry)
}
stations = do.call(c, stations)
names(geo.germany) <- names
names(stations) <- names
plot <- ggplot() +
geom_sf(data = geo.germany, aes(group=names(geo.germany)), colour = "red", fill = NA) +
geom_sf(data = stations, aes(group=names(stations))) +
transition_states(states = names(geo.germany)) +
shadow_mark(past = TRUE, alpha = 0.5, fill = "grey")