Most basic animation with R and Image Magick



This post describes how to build a basic count down .gif animation. It uses R to make 10 images, and Image Magick to concatenated them in a .gif.

Animation Section About line chart

This is probably the most basic animated plot (.gif format) you can do with R and Image Magick.

  • Start by building 10 images with R
  • Use Image magick to concatenate them in a gif

Of course, Image Magick must be installed on your computer. See here to install it.

Note: : This example has been found on Mark Heckmann’s R you ready website.

# Build 10 images -> save them at .png format
png(file="example%02d.png", width=480, height=480)
par(bg="grey")
  for (i in c(10:1, "G0!")){
    plot.new()
    text(.5, .5, i, cex = 6 )
  }
dev.off()

# Use image magick
system("convert -delay 80 *.png animated_count_down.gif")

# Remove png files
file.remove(list.files(pattern=".png"))

Related chart types


Line plot
Area
Stacked area
Streamchart
Time Series



❤️ 10 best R tricks ❤️

👋 After crafting hundreds of R charts over 12 years, I've distilled my top 10 tips and tricks. Receive them via email! One insight per day for the next 10 days! 🔥