I'm trying to create an animated GIF using tmap and display it in my Shiny app. When I use tm_shape() + tm_polygons() for a single date, the image produced is always OK. However, when I use tm_facets() and feed the result to tmap_animation, the resulting GIF has random dark green frames, as per the below.
Here is the code I am using the generate the animation:
data(World)
confirmed = read.csv('./data/time_series_covid_19_confirmed.csv', stringsAsFactors = T) %>%
select(-Province.State, -Country.Region) %>%
pivot_longer(!c('Lat', 'Long', 'iso3'), names_to = 'date', values_to = 'confirmed') %>%
mutate(date = as.Date(gsub('X', '', date), '%m.%d.%Y')) %>%
group_by(iso3, date) %>%
summarise(confirmed = sum(confirmed)) %>%
mutate(perc_change = 100 * ifelse(
lag(confirmed, default = 0) == 0 | confirmed < 1000 | lag(confirmed) > confirmed,
0,
(confirmed - lag(confirmed)) / lag(confirmed)
)
) %>%
inner_join(select(World, iso_a3, geometry), by=c('iso3' = 'iso_a3')) %>%
st_sf()
conf_anim = confirmed %>%
filter(date < '2020-02-28') %>%
tm_shape() + tm_polygons('perc_change', style='cont') +
# tm_fill('perc_change', palette='Blues', style='fixed',
# breaks=c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, Inf)) + tm_borders() +
tm_facets(along='date', free.coords = F)
tmap_animation(conf_anim, filename = './www/conf_anim.gif', delay=50)
Anyone know how I could fix this?