2

I am working on animating the path of boats through the Pacific. I have a data set with ship ID, lat, lon, and dates. I have successfully been able to plot the points on a map and animate the points.

Static Plot of Ship Paths

Once I animate the points, it appears to skip some points in the animation. Look at the differences in path on the static plot above vs. the gif plot below.

Gif Plot of Ship Paths

Example of the ship data frame info. There are 5 unique ship ID. Some ship ID have multiple lat/lon entries for each datetime. My assumption is that the animation is only revealing one lat/lon for each ship per datetime and thus skipping duplicates hence the missing points in comparison to the static plot.

ship lat lon datetime
382914 49.22597 -124.8141 2022-02-04
351364 54.16689 -179.9273 2022-02-22
... ... ... ...

Code for static plot image:

map1 <- ggplot() +
  geom_polygon(data=mapWorld, aes(x=long, y=lat, group=group), 
                              color= "darkolivegreen", 
                              fill="darkolivegreen") +
   geom_path(data = BOATS, aes(x=lon, 
                               y = lat,
                               group = ship id,
                               color = factor(ship)),
                               size = 1.5, show.legend = FALSE) +
  geom_point(data = BOATS, aes(lon, 
                               lat,
                               group = ship,
                               color = factor(ship)), 
                               alpha = 1, size = 2, shape = 21) +
  
 coord_sf(xlim=c(-180, -115), ylim=c(27,62), expand = FALSE) +
 labs(x="Longitude", 
      y="Latitude") +
 scale_colour_brewer(palette = "Dark2") +
 guides(colour = guide_legend(nrow = 3, 
                              byrow = TRUE, 
                              override.aes = list(size=5))) +
 mapTheme
  
map1

Code for animation:

library(gganimate)
library(gifski)

map1.animation =  map1 + 
                  transition_reveal(along = datetime) + 
                  ease_aes('linear') + 
                  enter_fade() + 
                  exit_fade() 
                
animate(map1.animation, fps = 30,
                        nframes = 360, 
                        width = 1071, 
                        height = 715)


anim_save("Boat Path.gif")
Phil
  • 7,287
  • 3
  • 36
  • 66
mcdejer
  • 41
  • 2
  • I am having the same problem with and number of distinct datasets. Did you find a way forward? – Amleto Mar 22 '23 at 00:02

0 Answers0