This function opens a graphical device (specified in
ani.options('ani.dev')) first to generate a sequence of images based
on expr, then makes use of the command convert in
‘ImageMagick’ to convert these images to a single animated movie (as a GIF or
MPG file). An alternative software package is GraphicsMagick (use
convert = 'gm convert'), which is smaller than ImageMagick.
This function calls im.convert (or gm.convert,
depending on the argument convert) to convert images to a single
animation.
The advantage of this function is that it can create a single movie file,
however, there are two problems too: (1) we need a special (free) software
ImageMagick or GraphicsMagick; (2) the speed of the animation will be beyond
our control, as the interval option is fixed. Other approaches in this
package may have greater flexibilities, e.g. the HTML approach (see
saveHTML).
See ani.options for the options that may affect the output,
e.g. the graphics device (including the height/width specifications), the
file extension of image frames, and the time interval between image frames,
etc. Note that ani.options('interval') can be a numeric vector!
library(animation)
## make sure ImageMagick has been installed in your system
saveGIF({
for (i in 1:10) plot(runif(10), ylim = 0:1)
})
## if the above conversion was successful, the option 'convert' should not be
## NULL under Windows
ani.options("convert")
## like 'C:/Software/LyX/etc/ImageMagick/convert.exe'
saveGIF({
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow")
}, movie.name = "brownian_motion.gif", interval = 0.1, nmax = 30, ani.width = 600)
## non-constant intervals between image frames
saveGIF({
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow")
}, movie.name = "brownian_motion2.gif", interval = runif(30, 0.01, 1), nmax = 30)
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).