1

I am using the animate function in R to successfully create the animation I require and it is displayed perfectly. However, I cannot save the output (called TodayMotion in the code example below) in a file (such as a Gif89a) so that I can distribute/store the animation. It sounds a simple problem but I have been unable to solve it.

I have attempted a wide range of solutions including the ImageMagick package which cannot load on my version of R. Also save.gif and the Magick package's write command, it says it does not recognise the file. And just to clarify I have tried 'magick::image_write(TodayMotion, path="magicksaveOption.gif")' & 'anim_save("TodayMotion.gif", TodayMotion)' and neither work.

ggm <- ggmap(UK) +
geom_point(data = Origin1,
aes(x = Long, y = Lat,
colour = group),
size = 2, alpha = 0.8) +
transition_time(time) +
shadow_wake(wake_length = .1)


TodayMotion <<- animate(ggm, height = 1500, width = 1500, fps = 
20, duration = 20, start_pause = 10, end_pause = 20,  rewind = T)

PS. in the environment TodayMotion is described as a "class gif_image"

I would like to end up with a saved gif (gif89a as it is animated) in my desired directory. (the image below is captured from the screen)

enter image description here

LostAtSea
  • 37
  • 1
  • 6
  • 1
    May you produce the whole code so your example can be reproduced, please? – LocoGris Feb 17 '19 at 10:59
  • I suspect that your full code is rather elaborate. Even better would be to produce a simple test example that uses short code to illustrate your problem. – G5W Feb 17 '19 at 11:33
  • The code is rather complex and is not really the issue, the animation works perfectly and does precisely what it says. But what I am left with is the TodayMotion file, but I cannot save it. It is that simple, I just want to save it in, a format I can send to others, presumably gif which can store the animation. I have tried for hours and the soultion might be obvious but I cannot find it. – LostAtSea Feb 17 '19 at 11:54
  • See the answer here and its comment: https://stackoverflow.com/questions/51440496/using-gganimate-to-export-gif – Stéphane Laurent Feb 17 '19 at 13:20
  • That only works for gganimate, not animate as I have tried it. But thanks anyway. It is a perplexing problem that initially seems simple and you would expect an automatic solution, but I can find none. – LostAtSea Feb 17 '19 at 13:54

2 Answers2

2

You can right-click the viewer pane I Rstudio and choose save. Default saving option Is a .gif

Steen Harsted
  • 1,802
  • 2
  • 21
  • 34
  • Yes true, but I need a solution in the code as this is a function in part of a larger program and a file has to end up in a fixed directory. – LostAtSea Feb 17 '19 at 13:56
1

The answer, in the end, is, courtesy of Stephane Laurent, is anim_save(DFCFileName, TodayMotion). When nothing else worked this did. I would show you the result but the size limit is 2MB and this is 19MB! You can do some excellent animation utilising the TweenR package for interpolation, then animate. TweenR really smooths out any jerkiness and gives excellent results.

LostAtSea
  • 37
  • 1
  • 6