简体   繁体   English

构建网络时边和顶点属性映射不正确Dynamic object

[英]Edge and vertex attributes not mapping properly when constructing networkDynamic object

My aim is to make a dynamic network visualization using the ndtv and networkDynamic packages in R.我的目标是使用 R 中的 ndtv 和 networkDynamic 包进行动态网络可视化。 I constuct the networkDynamic object using edge spells and vertex spells as described in section 7.3 here .我使用边缘拼写和顶点拼写构建 networkDynamic object ,如第 7.3 节所述。 The data frames also contain temporal edge and vertex attributes (TEAs).数据帧还包含时间边缘和顶点属性 (TEA)。

library(networkDynamic)
edges <- read.csv("https://raw.githubusercontent.com/SoranHD/Rstuff/main/edges.csv")
edges$X<- NULL
nodes <- read.csv("https://raw.githubusercontent.com/SoranHD/Rstuff/main/nodes.csv")
nodes$X <- NULL
net <- networkDynamic(edge.spells = edges, vertex.spells = nodes, create.TEAs = TRUE)

I want all edges and vertices to remain active throughout, but to vary based on their TEAs.我希望所有边和顶点始终保持活动状态,但会根据它们的 TEA 而有所不同。 I want "weight" to determine the width of the edges and "size" to determine the size of the nodes.我想要“权重”来确定边缘的宽度,“大小”来确定节点的大小。

However, when I render the animation, it is clear that neither map onto their object properly.但是,当我渲染 animation 时,很明显 map 都没有正确地放到他们的 object 上。

compute.animation(net, 
              slice.par = list(start = 1, end = 8, interval = 1, aggregate.dur = 1, rule = "any"))
render.d3movie(net, usearrows = T,
           edge.lwd = (net %e% "weight.active")/100,
           vertex.cex = (net %v% "size.active"),
           output.mode = "HTML",
           launchBrowser = FALSE)

For some reason, only the edges directed from "node 1" have different widths, and even these do not appear as expected.出于某种原因,只有从“节点 1”指向的边具有不同的宽度,甚至这些边也没有按预期显示。 The node sizes are also wrong, and remain static throughout.节点大小也是错误的,并且始终保持 static。

Clearly I am doing something wrong.显然我做错了什么。 I have tried to construct the data set in several different ways, including as a list of network objects representing each wave, but I keep running into the same issue.我尝试以几种不同的方式构建数据集,包括作为代表每个波的网络对象列表,但我一直遇到同样的问题。 Any help would be greatly appreciated.任何帮助将不胜感激。

Edit编辑

I have had the same issue when constructing the dynamicNetwork object using the network.list option, and it persists when running the same code on the newcomb data, as suggested in the comments.我在使用 network.list 选项构建 dynamicNetwork object 时遇到了同样的问题,并且在新梳数据上运行相同的代码时它仍然存在,如评论中所建议的那样。 The documentation linked above mentions that the data set contains the edge attribute "weights" it doesn't seem to, so I use the "rank" attribute from the newcom.rank data set instead.上面链接的文档提到数据集包含它似乎不包含的边缘属性“权重”,因此我使用 newcom.rank 数据集中的“rank”属性。

library(networkDynamic)
library(networkDynamic)
data(newcomb)
newcombDyn <- networkDynamic(network.list = newcomb.rank, create.TEAs = TRUE)

When comparing the "rank" attribute in the first network in the newcomb.rank network list with the "rank.active" attribute at time 1, we see that they do not correspond.当比较 newcomb.rank 网络列表中第一个网络中的“rank”属性与时间 1 的“rank.active”属性时,我们发现它们不对应。 Moreover, the "rank.active" attribute is much larger than the number of active edges.此外,“rank.active”属性远大于活动边的数量。

get.edge.attribute(newcomb.rank[[1]], "rank")
get.edge.attribute.active(newcombDyn, "rank.active", at = 1)

Moreover, "rank.active" looks the same at t = 2 as t = 1.此外,“rank.active”在 t = 2 时看起来与 t = 1 时相同。

get.edge.attribute.active(newcombDyn, "rank.active", at = 2)

Finally, when rendering the animation with edge width based on the "rank.active" attribute, the edge width is not dynamic but remains static throughout.最后,当使用基于“rank.active”属性的边缘宽度渲染 animation 时,边缘宽度不是动态的,但始终保持 static。

    compute.animation(newcombDyn, slice.par = list(start = 1, end = 14, interval = 1, aggregate.dur = 1, rule = "any"))
render.d3movie(newcombDyn, usearrows = T, edge.lwd = (newcombDyn %e% "rank.active")/2, output.mode = "HTML", launchBrowser = TRUE)

I think it is just a matter of changing from rank.active to rank , but the results may not be what you desire as all relationships through time are present as there are no ties allowed.我认为这只是从rank.active更改为rank的问题,但结果可能不是您想要的,因为随着时间的推移,所有关系都存在,因为不允许有联系。 But,但,

library(networkDynamic)
library(ndtv)
data(newcomb)
newcombDyn <- networkDynamic(network.list = newcomb.rank, create.TEAs = TRUE)

Looking at the difference between看看两者的区别

get.edge.value.active(newcombDyn, 'rank', onset=0, terminus=1,  dynamic.only=TRUE)

and

get.edge.value.active(newcombDyn, 'rank', onset=1, terminus=2,  dynamic.only=TRUE) 

we see the values are changing so should map as expected (perhaps)我们看到值正在改变,所以 map 应该像预期的那样(也许)

render.d3movie(newcombDyn, usearrows = T, edge.lwd = (newcombDyn %e% "rank")/2, output.mode = "HTML", launchBrowser = TRUE)

makes a movie of sorts.制作某种电影。 Alternatively,using your data from above (now that it has been certified as safe by the author), changing your或者,使用上面的数据(现在它已被作者证明是安全的),更改您的

render.d3movie(net, usearrows = T,
          edge.lwd = (net %e% "weight.active")/100,
          vertex.cex = (net %v% "size.active"),
          output.mode = "HTML",
          launchBrowser = FALSE)

to

render.d3movie(net, usearrows = T,
           edge.lwd = (net %e% "weight.active")/25, #divide by 100 makes invisible arrows
           vertex.cex = (net %v% "size.active")*2, # perhaps too large, but...
           output.mode = "HTML",
           launchBrowser = FALSE)

And it seems to be working(ish), for a remarkably tricky data structure.对于一个非常棘手的数据结构,它似乎正在工作(ish)。 HTH高温高压

Because the rendering function already computes a static 'slice' network at each time step (with network.collapse ) it is possible to directly pass in the name of the static version of the attribute ('size' vs 'size.active') to be used in the rendering function: Because the rendering function already computes a static 'slice' network at each time step (with network.collapse ) it is possible to directly pass in the name of the static version of the attribute ('size' vs 'size.active') to用于渲染 function:

> render.d3movie(net, usearrows = T,
                                 edge.lwd = 'weight',
                                 vertex.cex = 'size',
                                 output.mode = "HTML",
                                 launchBrowser = FALSE)

But in this case, you also want to transform the the attribute for rendering, you can pass in a function to be applied (see examples in ?render.animation ) The function can use the variable named slice that corresponds to the appropriate network for that time slice:但是在这种情况下,您还想转换属性以进行渲染,您可以传入要应用的 function (请参见?render.animation中的示例)使用slice对应的变量 ZC1C425268E68385D14AB5074C17A9时间片:

> render.d3movie(net, usearrows = T,
                 edge.lwd = function(slice){slice%e%'weight'/100},
                 vertex.cex = function(slice){slice%v%'size'},
                 output.mode = "HTML",
                 launchBrowser = FALSE)

It looks like you have defined edges to be active between all vertices at all time steps, but the vertices are not defined to active at all time steps.看起来您已将边定义为在所有时间步的所有顶点之间都处于活动状态,但顶点并未定义为在所有时间步内都处于活动状态。 For example there are only 9 vertices active at time step one.例如,在时间步一只有 9 个顶点处于活动状态。 You could change your input file to align vertex and edge activity.您可以更改输入文件以对齐顶点和边缘活动。 You could also use reconcile.vertex.activity() to expand the activity of the vertices (but it won't be able to infer the TEA attributes for the missing time ranges)您还可以使用reconcile.vertex.activity()来扩展顶点的活动(但它无法推断缺失时间范围的 TEA 属性)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM