Animating a graph

Apr 21 2017 Published by under bibliometrics, information analysis

What I really want is an interactive network graph that my viewer can click on, slide things, flip switches, etc. I'll get there someday. In the mean time, this was fairly easy to show the evolution of a network over time.

The network is a company network generated in Quid*. I used the time filter and exported a png every 3-5 years for this network. The point being that there has been a lot of growth and in particular clusters of companies.

Here it is:

Probably need to click to enlarge to see the animation

ImageMagick is an awesome open source image tool. There have been other ways to get to it from R or python, but the magick package is the easiest I've seen. The vignettes and a blog post from rOpenSci were helpful.

 

library("magick", lib.loc="~/R/win-library/3.3")
setwd("I:/Christina's/person")
newcomp_files<-list.files("folder", pattern="*.png", full.names=TRUE)
newcomp<-lapply(newcomp_files, image_read)
#need image_join because the above produces a list instead of a magick vector 
#dispose deletes previous image
newcomp_animate<-image_animate(image_join(newcomp), fps = 0.5, dispose = "previous")
image_write(newcomp_animate, 'newcomp_animate_82-.gif')

 
Note: the final version you see also used magick to crop (not great) and to annotate with the year. I slowed the frame rate down quite a bit.
 

I tried morphing and it was pretty slow and really not worth it so much.

*not affiliated and not endorsing

No responses yet

Leave a Reply