animating maps issues and questions

Hi Everyone I was wondering if i can get some help with gganimate and package sf please. I have created code that works in principle but not exactly what i want as output. See below:

wpg_animation <- ggplot(obj1$geometry) +
  geom_sf(color = "black", fill = "lightgreen") +
  xlab("Longitude") + ylab("Latitude") + 
  annotation_scale(location = "br", width_hint = 0.5) +
  theme(panel.grid.major = element_line(color = "white", linetype = "dashed", size = 0.5)) +
  ## gganimate part
  labs(title = 'Elevation: {closest_state}') +
  transition_states(obj1$Elevation, 
                    transition_length=.5, 
                    state_length=2) +
  ease_aes("linear")

the output is as follows

Now my problems are as follows, along with desired outcome states:

  1. its not outputting the entire city geometry - i wish for the city geometry to stay in the background
  2. I wanted to create another variable (called flooding perhaps) in that if water level is greater than elevation level in the neighbourhood centroid then that neighbourhood polygon turns blue (not green)
  3. how do you control the amount of *.png files gganimate creates? because really i just want 1 png file per elevation level.

any help appreciated!

take care!

could you provide a reprex please ?

Hi, thanks for your reply! Apologies, i'm not sure exactly what to reprex because the code i posted works, but i guess what im asking is, is there anything missing from my code to output the full map, along with my other issues?

i dont have an issue reprex'ing, but im not too sure what to reprex because i dont know what else i should code to provide a reprex.

It is not easy to troubleshoot your code without access to your data.

For a reproducible example of an animated map built with {ggplot2} and {gganimate} on top of a spatial object consider this post:

It is a part of a longer thread about visualizing spatial data and it is built on the widely available North Carolina shapefile (it ships with {sf}, so just about everybody has access to it).

Have a look at it and if your doubts remain come back to me, I would be happy to help.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.