0

I am creating an animation of a changing social network in R package NDTV. I have a list of vertices I would like to have grouped together during a short period of the animation. What is the best way to do this?

I've pursued three different avenues, but failed in all of them. Any suggestions would be appreciated.

1) I've tried using a vertex attribute called "group", on the understanding that this will enable me to associate a vertex with a group. Using the 'wheel' animation in ndtv workshop as my starting point, I've attempted to deploy the following code:

activate.vertex.attribute(wheel,'group','2',onset=6,terminus=8,v=1) render.animation(wheel,vertex.group='group',verbose=FALSE)

But this brings up the error message: "group is not a graphical parameter."

This is puzzling because when I run list.vertex.attributes(wheel), group.active is listed as an attribute. Color.active also is listed as an attribute, and I am able to change the color of vertices using the method described above. Why is one attribute recognized by the program while the other is not?

2) I've also tried uploading a csv file comprised of x coordinates and y coordinates, in the hopes that I can use this to dictate the position of the vertices. I was able to upload the csv file and create a static plot with the new coordinates, but I wasn't able to incorporate the new coordinates into the changing animation of that plot. Here's the data and code I used (again, this code was deployed after initializing the network as described in the ndtv workshop)

df<-read.csv(file="coords.csv",header=F,sep=",") plot(wheelAt8,coords=df)

This results in a static graph that reflects the uploaded coordinates, but the animation itself is not changed.

3) Because I couldn't get the above to work, I am now trying to modify network.layout.animate.useAttribute(net, dist.mat = NULL, default.dist = NULL,seed.coords = NULL, layout.par = list(x = "x", y = "y"), verbose = TRUE) for this project.
I'm not sure where to start because I am not sure how to put coordinate values into "x".

Thank you for your time.

oymonk
  • 427
  • 9
  • 27

1 Answers1

1

The ndtv package attempts to position vertices according to the distances along their edges, so simply adding an attribute named group will not accomplish this. You would need to either modify the structure of the network (activate and deactivate edges between vertices in your 'group') or override the animation process entirely and just tell it exactly where you want the vertices drawn (what you try in attempt #2)

In your example render.animation(wheel,vertex.group='group',verbose=FALSE) will not work because there is no plot parameter named vertex.group. If you wanted to color the vertices by group, you would do something like

render.animation(wheel,vertex.col='vertex.group')

which tells it to use the 'vertex.group' attribute as the vertex color

In attempt #2, you provide only a static set of coordinates, so I'm assuming you want the vertices to stay in fixed positions and just animate tie changes? To do this, you need to attach your coordinates to the network as attributes named 'x' and 'y'. Then, since you want to use a non-default network layout algorithm, you need to call compute.animation and tell it what layout to use before you call render.animation.

library(ndtv)

# the 'wheel' example network
wheel <- network.initialize(10)
add.edges.active(wheel,tail=1:9,head=c(2:9,1),onset=1:9, terminus=11)
add.edges.active(wheel,tail=10,head=c(1:9),onset=10, terminus=12)

# your coordinate amtrix
df<-matrix(c(-0.99603723, 2.798261858,
             -0.10480299, 1.754082668,
             0.64294818, 0.679889124,
             1.19137571, 0.042572219,
             1.47703967, 0.250050715,
             1.49393321, 1.523045819,
             1.2319355, 3.772612788,
             0.72715205, 6.634426198,
             0.01328487, 9.529656458,
             -1.49393321, 0.662555779),ncol=2,byrow=TRUE)

# attach your *static* coordinates to the network
set.vertex.attribute(wheel,'x',df[,1])
set.vertex.attribute(wheel,'y',df[,2])

# compute the animation with the 'useAttribute' layout (which will look for x and y attributes)
compute.animation(wheel,animation.mode = 'useAttribute')
# render it
render.animation(wheel)
skyebend
  • 1,079
  • 6
  • 19
  • Thank you for getting back to me, and apologies for confusion in the way I worded my request. To make more clear what I want to achieve, I created an animation [here](http://www.archivalscience.ca/communities.gif). Note: animation starts after five seconds. Also note: it only seems to be working in Chrome. The problem I'm finding is that communities of vertices (determined using the fast greedy algorithm) are not located together in the R display window when I run the animation using NDTV. If you have the time, can you tell me if what I want to achieve is even possible? – oymonk Sep 29 '15 at 19:10
  • This seems like too general a question for SO, better posted (with data examples) to the statnet help listserv https://mailman13.u.washington.edu/mailman/listinfo/statnet_help – skyebend Sep 29 '15 at 21:47