Question

I am making an animation using the igraph and animation packages. I want to watch the change in edges by animating through a data.frame 1 row at a time. I have create a list of igraph objects and would like to make sure all social actors are represented even if their row hasn't come up yet. They would become isolates until a later animation.

How can I add an actor into an igraph object as an isolate. I'm using a layout.circle and want to keep the actors in a consistent placement.

I'll start with data (the igraph object) and then some visuals to show what I want.

g <- structure(list(4, TRUE, c(0, 1, 2, 0), c(1, 2, 0, 3), c(0, 3, 
    1, 2), c(2, 0, 1, 3), c(0, 2, 3, 4, 4), c(0, 1, 2, 3, 4), list(
        c(1, 0, 1), structure(list(), .Names = character(0)), structure(list(
            name = c("greg", "teacher", "sam", "sally"), size = c(10, 
            10, 10, 10)), .Names = c("name", "size")), structure(list(
            wc = c(5L, 4L, 10L, 5L), id = 2:5, prop_wc = c(0.208333333333333, 
            0.166666666666667, 0.416666666666667, 0.208333333333333
            ), color = c("grey50", "grey50", "grey50", "grey50"), 
            width = c(3.125, 2.5, 6.25, 3.125)), .Names = c("wc", 
        "id", "prop_wc", "color", "width")))), class = "igraph")


library(igraph)
plot(g, layout=layout.circle)

## vector of actors to include in this order
## in the igraph object there is no "researcher" or "End" actor
actors <- c("greg", "teacher", "sam", "sally", "researcher", "End")

This plots as:

enter image description here

I would like (don't worry about the line width weightings):

enter image description here

So the animation sequence would be something like this (all actors are included at each frame):

enter image description here

If I can add the isolates c("researcher", "End") to the igraph above I can generalize to each frame.

I thought it might be as easy as:

V(g) <- actors

but it is not.

Was it helpful?

Solution

The trick I used to achieve this was to prerender the layout and have every node and edge pre-formatted as invisible until their time would come.

  1. render layout L for full graph
  2. everything is invisible at first (hsv(.36,1,1,alpha=0))
  3. loop:
    1. make nodes/edges visible as soon as they are supposed to show up (hsv(.36,1,1,alpha=1))
    2. plot graph (with initially calculated and constant layout L) and save as png
  4. glue everything together using ffmpeg

main article with animations:

http://www.joyofdata.de/blog/animated-visualization-of-a-growing-network-of-carpoolings/

code:

http://www.joyofdata.de/blog/r-code-for-igraph-animation/

OTHER TIPS

Although not directly compatible with igraph, the R package networkDynamic has appropriate representations for dynamic networks, which can then be rendered as movies or exported as HTML5 animations using the ndtv R package. If you post a data.frame with your data (looks like your example just has the first network?) I could give you an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top