DS4PS / cpp-527-fall-2020

http://ds4ps.org/cpp-527-fall-2020/
0 stars 1 forks source link

Animation not working for problems #12

Open JasonSills opened 4 years ago

JasonSills commented 4 years ago

Hi @lecy

I've tried to get the animation package to work, but it will not produce an animation. The GIFs are only blank screens. I went to https://yihui.org/animation/ to test some animations there and the animations won't work. For example, I ran:

library(animation) ani.options(interval = 0.2, nmax = 100)

should be close to 1/6

MC.hitormiss()$est

and I was returned a series of images, not an animation. Any ideas? I have Image Magick installed. When I installed animation I was not prompted to click the option “Install legacy components (convert.exe etc). I've uninstalled and reinstalled a couple of times, but I'm never prompted. Sills test

lecy commented 4 years ago

This is a case where the R package is utilizing a 3rd party program platform for the task, and R is just calling the 3rd party app when needed.

Many packages leverage this type of functionality (thus you can script your entire process so the analysis can be extended or the code can be re-used for other animations in the future).

However, some programs can be harder to use than others. I have not found Image Magik to be especially robust. It has always taken awhile to get it installed and configured correctly. There are lots of resources if you google around. Just takes some time.

Alternatively, if I am doing a simple animation I will often create the image files directly then use one of the free GIF creators online. Just search for image to GIF sites and you will get a bunch of options like this one:

https://gifmaker.me/

They all work similarly - the code generates a bunch of static images, then the animation component of the software stitches them together into a GIF.

You could probably go directly from this folder of images you currently have to test it out.

For this exercise the important take-away is recognizing how animations are designed using loops that manipulate the moving components of the graphs.

The annoying details about installing Image Magik and configuring all settings correctly might not be worth spending your time on unless you want to develop expertise in these types of visualizations.

lecy commented 4 years ago

You save images from plots in R by opening an image writing connection and closing it with dev.off().

png(file = "myplot.png", bg = "transparent")
plot(1:10)
rect(1, 5, 3, 7, col = "white")
dev.off()

It looks a little odd because you don't pass an image object to the png() function. This is because graphs might require dozens of lines of code, so the png() function designates the start of the graphic, and the dev.off() the end of the step writing the graphic to a file.

Just make sure you change the file name inside a loop so you don't save the same image 1,000 times, over-writing the previous version each time.

Reference:

https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/png.html