弄清楚NDTV中顶点组如何形成和消解

时间:2015-09-27 02:47:39

标签: r animation statnet

我正在R包NDTV中创建一个不断变化的社交网络的动画。我有一个我希望在动画的短时间内组合在一起的顶点列表。做这个的最好方式是什么?

我追求三种不同的途径,但都失败了。任何建议,将不胜感激。

1)我已经尝试使用名为" group"的顶点属性,理解这将使我能够将顶点与组关联。使用'轮'以ndtv workshop中的动画作为我的起点,我尝试部署以下代码:

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

但这会显示错误消息:" group不是图形参数。"

这很令人费解,因为当我运行list.vertex.attributes(wheel)时,group.active被列为属性。 Color.active也被列为属性,我可以使用上述方法更改顶点的颜色。为什么一个属性被程序识别而另一个属性不是?

2)我还尝试上传一个由x坐标和y坐标组成的csv文件,希望我可以使用它来指定顶点的位置。我能够上传csv文件并使用新坐标创建静态图,但我无法将新坐标合并到该图的更改动画中。这里是我使用的data和代码(再次,这个代码是在ndtv研讨会中描述的初始化网络之后部署的)

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

这会产生一个反映上传坐标的静态图形,但动画本身不会改变。

3)因为我无法完成上述工作,我现在正在尝试修改此项目的network.layout.animate.useAttribute(net, dist.mat = NULL, default.dist = NULL,seed.coords = NULL, layout.par = list(x = "x", y = "y"), verbose = TRUE)
我不确定从哪里开始,因为我不确定如何将坐标值放入&#34; x&#34;。

感谢您的时间。

1 个答案:

答案 0 :(得分:1)

ndtv包尝试根据边缘的距离定位顶点,因此只需添加名为group的属性就无法完成此操作。您需要修改网络的结构(激活和停用“组”中顶点之间的边缘)或完全覆盖动画过程,并准确告诉它您想要绘制顶点的位置(尝试尝试#2)

在您的示例中,render.animation(wheel,vertex.group='group',verbose=FALSE)将无效,因为没有名为vertex.group的绘图参数。如果您想按组对顶点着色,您可以执行类似

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

告诉它使用'vertex.group'属性作为顶点颜色

在尝试#2中,您只提供一组静态坐标,所以我假设您希望顶点保持固定位置并且仅仅为关系更改动画?为此,您需要将坐标作为名为“x”和“y”的属性附加到网络。然后,由于您要使用非默认网络布局算法,因此在调用compute.animation之前,需要调用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)