Sample data
library(raster)
library(ggplot2)
my.shp <- getData('GADM', country = 'FRA', level = 1)
plot(my.shp)
If I want to plot this data using ggplot:
my.shp_f <- fortify(my.shp, region = "ID_1")
ggplot(data = my.shp_f, aes(long, lat, group = group)) + geom_polygon(fill = "grey80")
Question 1: Why has administrative boundary disappeared?
Question 2: I have another dataframe which has 2 years of daily rainfall data from day 1 to day 365 of for each of the administrative divisions.
rain.data <- data.frame(ID_1 = rep(my.shp@data$ID_1, each = 2 * 365),
year = rep(rep(1981:1982, each = 365), times = 2),
day = rep(1:365, times = 4),
rain = sample(1:20, replace = T, 2 * 365 * 2))
I want to create an animation of daily rainfall for this shape file going from day 1 1981 to day 365 1982.
My overall approach at the moment is to make a loop and save rainfall map of each day as individual .png
file and then stack those files as .gif
.
However, this results in me saving 2 years X 365 days worth of .png
files first and then stack them together. If I have 30 years worth of data, this becomes impossible. I read this post about gganimate
https://github.com/thomasp85/gganimate and wondered if someone can
demonstrate how to generate an animated map using gganimate using the data above