2

I'm animating a map with percentage of deaths in Africa caused by HIV/AIDS. For some years the animation works well, but for other years the countries are sort of jumping around. The data can be found here. My code is shown below

library(sf)
library(rworldmap)
library(transformr)
library(gganimate)
library(tidyverse)

mortality <– read_csv("path_to_file")

africa_map <- getMap(resolution = "low") %>% st_as_sf() %>% 
 filter(continent == "Africa")

mortality %>% filter(region == "Africa", disease == "HIV/AIDS") %>% 
 mutate(year = as.integer(year(year))) %>% drop_na() %>% 
 left_join(africa_map, by = c("country_code" = "SOV_A3")) %>% 
 ggplot() + geom_sf(aes(fill = percent)) +
 transition_time(year) +
 labs(title = "Year: {frame_time}")

Any idea how to fix this?

0 Answers0