Closed bensoltoff closed 7 years ago
When I leave the underscore in it says no such function found. I saw some examples online without the underscore so i tried that. Still not able to produce an animation on my end.
Also i realized I named two objects 'p' so the one that you are seeing is not the world map I made, but a ggplot I tried to troubleshoot with.
I feel like some default packages may not be loading correctly. In class, I was able to create a map only loading the package maps and ggplot2. At home I had issues and had to load dyplr and tibble as packages in order to save a map_data
Running this code chunk on my computer:
library(tidyverse)
library(gganimate)
# get fertility data
fert <- read_csv("FertilityHistory2.csv")
fert
# tidy the data frame
fert_tidy <- fert %>%
gather(year, fertility, -Country, convert = TRUE)
fert_tidy
# get world geodatabase
world <- map_data("world")
# test the plot on just a few years of data
p <- fert_tidy %>%
filter(year > 2000, year < 2003) %>%
ggplot(aes(map_id = Country, frame = year)) +
geom_map(aes(fill = fertility), map = world) +
expand_limits(x = world$long, y = world$lat) +
labs(title = "Fertility rate",
fill = NULL) +
ggthemes::theme_map() +
coord_map(projection = "mollweide", xlim = c(-180, 180))
gg_animate(p, filename = "fertility_year.gif")
Produces this image file:
This is just on a two year sample of data. If you want to animate the entire 200+ year history of fertility, it just takes a long time for the computer to animate each frame.
@DanaWestley When I run the following code:
I don't get an error. Remember that the package is called
gganimate
but the function is calledgg_animate()
. This creates the following image: