oymonk
oymonk

Reputation: 365

Making clear how groups of vertices form and dissolve over time in NDTV

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.

Upvotes: 0

Views: 275

Answers (1)

skyebend
skyebend

Reputation: 1109

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)

Upvotes: 1

Related Questions