r语言 - 在NDTV中,弄清楚顶点群是如何随着时间的推移而形成和消失的



我正在用R包NDTV制作一个不断变化的社交网络动画。我有一个顶点列表,我想在动画的短时间内分组在一起。最好的方法是什么?

我尝试过三条不同的途径,但都失败了。任何建议都将不胜感激。

1)我试过使用一个叫做"group"的顶点属性,基于这样的理解,这将使我能够将顶点与组相关联。使用ndtv workshop中的"wheel"动画作为我的起点,我尝试部署以下代码:

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文件并使用新坐标创建一个静态绘图,但我无法将新坐标合并到该绘图的变化动画中。以下是我使用的数据和代码(同样,这些代码是在初始化网络之后部署的,如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)为这个项目。
我不确定从哪里开始,因为我不确定如何将坐标值放入"x"。

谢谢你的时间。

ndtv包尝试根据沿其边缘的距离来定位顶点,因此简单地添加一个名为group的属性将无法完成此操作。你需要修改网络的结构(在你的"组"中激活和取消顶点之间的边)或者完全重写动画过程,只告诉它你想要绘制顶点的确切位置(你在尝试#2中尝试的)

在您的示例中,render.animation(wheel,vertex.group='group',verbose=FALSE)将无法工作,因为没有名为vertex.group的plot参数。如果你想按组给顶点上色,你可以输入

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

告诉它使用"顶点"。将'属性分组为顶点颜色

在尝试#2中,你只提供了一组静态坐标,所以我假设你想让顶点保持在固定位置,只是动画变化?为此,您需要将坐标作为名为"x"one_answers"y"的属性附加到网络上。然后,由于您希望使用非默认的网络布局算法,因此需要在调用render.animation之前调用compute.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)

最新更新