0

I am trying to create a network animation that shows how nodes change state over time. The use case is contact tracing for Covid-19. I used an agent-based model to simulate Covid-19 spread. From this I extracted my contact network. I am struggling to figure out how the tsna package changes node color (disease state) per time slice. Here is my data and attempt at rendering:

# load libraries

require(sna)
require(tsna)
require(ndtv)

# get data

url <- "https://github.com/aterhorst/data/blob/master/dynamic_network.Rdata?raw=true"
download.file(url, destfile= "data/dynamic_network.Rdata", mode = "wb")

# load data

load("data/dynamic_network.Rdata")

# create a dynamic network object

nd <-networkDynamic(edge.spells = edges,
                    vertex.spells = nodes)

# render dynamic network object

compute.animation(nd,
  animation.mode = "kamadakawai",
  slice.par = list(
    start = 1,
    end = 12,
    interval = 1,
    aggregate.dur = 2,
    rule = "any"))


render.d3movie(nd,
  vertex.col = nodes$col,
  displaylabels = TRUE)

Because my agent-based model is quite small, edges disappear around day 12. Essentially, everybody has been exposed to the virus by then so further contacts make no difference. My model stops caring. What you see in my example are static node colors. What I want to see are nodes changing color with disease state. Can someone help me get this right?

aterhorst
  • 625
  • 4
  • 14

1 Answers1

0

I simply added the following to the networkDynamic statement:

nd <-networkDynamic(edge.spells = edges,
                    vertex.spells = nodes,
                    create.TEAs = TRUE)

I tried to specify vertex.TEA.names = "col" and that threw things. Leaving it out solved my issue.

The TEAs thing is quite baffling and the online tutorials could explain this bit better for numbskulls like me. That said, it's free software and I am grateful to the creators of sna/tsna/ndtv for their contribution.

aterhorst
  • 625
  • 4
  • 14