I'm looking to recreate this sort of visualization How to create contour with wind animation using gganimate? with a time series wind speed data set, but I am encountering this error and can't figure out what's causing it:
Warning message: Computation failed in
stat_contour_fill()
: Supplied 2 columns to be assigned an empty list (which may be an empty data.table or data.frame since they are lists too). To delete multiple columns use NULL instead. To add multiple empty list columns, use list(list()).
The code:
pacman::p_load(ggplot2, tidyr, dplyr, raster,rgdal,sf,tidyverse,sp, gganimate, maptools, plyr, transformr, readxl, ggmap)
scale.breaks = scales::fullseq(range(test$speed), size = 10)
tim <- get_stamenmap(bbox = c(left = -105.2545,
bottom = 35.58840,
right = -105.6946,
top = 36.19384),
maptype = "terrain",
crop = FALSE,
zoom = 11)
map.annotation <- list(
annotation_raster(tim %>% unlist() %>%
alpha(0.4) %>% # change alpha setting for map here
matrix(nrow = dim(tim)[1],
byrow = TRUE),
xmin = attr(tim, "bb")$ll.lon,
xmax = attr(tim, "bb")$ur.lon,
ymin = attr(tim, "bb")$ll.lat,
ymax = attr(tim, "bb")$ur.lat),
coord_quickmap(xlim = c(attr(tim, "bb")$ll.lon, attr(tim, "bb")$ur.lon),
ylim = c(attr(tim, "bb")$ll.lat, attr(tim, "bb")$ur.lat),
expand = FALSE))
p.base <- ggplot(test, aes(x = longitude, y = latitude, z = speed))
p.base +
geom_contour_fill(breaks = scale.breaks) +
facet_wrap(~DateTime) +
map.annotation +
scale_fill_gradient(low = "green", high = "red",
aesthetics = c("colour", "fill"),
limits = range(scale.breaks)) +
theme_minimal()
data:
tibble::tribble(
~speed, ~dir, ~longitude, ~latitude, ~DateTime,
8.6, 269, -105.265514515, 35.4631886028, as.POSIXct("2022-04-01 20:11:00"),
8.3, 271, -105.25959775, 35.4632014724, as.POSIXct("2022-04-01 20:11:00"),
8.5, 273, -105.253680981, 35.463214052, as.POSIXct("2022-04-01 20:11:00"),
8.9, 272, -105.247764209, 35.4632263417, as.POSIXct("2022-04-01 20:11:00"),
9.3, 266, -105.241847433, 35.4632383413, as.POSIXct("2022-04-01 20:11:00"),
9.1, 259, -105.235930653, 35.4632500508, as.POSIXct("2022-04-01 20:11:00"),
7.9, 260, -105.230013871, 35.4632614704, as.POSIXct("2022-04-01 20:11:00"),
7.7, 271, -105.224097085, 35.4632725999, as.POSIXct("2022-04-01 20:11:00"),
8.4, 278, -105.218180295, 35.4632834394, as.POSIXct("2022-04-01 20:11:00"),
9, 276, -105.212263503, 35.4632939889, as.POSIXct("2022-04-01 20:11:00"),
)