我正在研究政府机构如何随时间变化。计划是使用 ndtv 包来可视化更改。但是,我遇到了问题,不知道我做错了什么!我怀疑我的数据格式不正确。
我有一个节点列表,其中列出了顶点 ID、代理名称、节点起始和节点终点:
nodelist <- read.csv("https://github.com/aterhorst/data/raw/master/edgelist.csv", header=T, stringsAsFactors = F)
和一个边缘列表,显示边缘的起点和终点:
edgelist <- read.csv("https://github.com/aterhorst/data/raw/master/edgelist.csv", header=T, stringsAsFactors = F)
我可以很容易地创建一个网络对象:
library(tidyverse)
library(sna)
nw <- network(edgelist %>% select(head, tail),
vertex_attr = nodelist %>% select(vertex.id, agency),
vertex.attrnames = c("vertex.id", "agency"),
directed = F)
print(nw)
plot(nw)
现在我想做一个动态网络对象:
library(tsna)
library(ndtv)
dn <- networkDynamic(nw,
edge.spells = edgelist,
vertex.spells = nodelist)
然后车轮脱落:
Error in networkDynamic(nw, edge.spells = edgelist, vertex.spells = nodelist) :
vertex.spells requires the vertex.id column to be numeric
我尝试将起始、终点从整数更改为数字 - 没有区别。我尝试了不同的方法来创建动态网络对象,例如
dn <- networkDynamic(edge.spells = edgelist)
这会产生此错误:
Initializing base.net of size 2020 imputed from maximum vertex id in edge records
Error in activate.edges(base.net, onset = edge.data[, 1], terminus = edge.data[, :
Onset times must precede terminus times in activate.edges.
和:
dn <- networkDynamic(edge.spells = edgelist, vertex.spells = nodelist)
给我这个错误:
Error in networkDynamic(edge.spells = edgelist, vertex.spells = nodelist) :
vertex.spells requires the vertex.id column to be numeric
我玩弄了 edge.spell 的顺序,这产生了积极的结果:
dn <- networkDynamic(net,
edge.spells = edgelist %>% select(onset, terminus, tail, head))
Edge activity in base.net was ignored
Created net.obs.period to describe network
Network observation period info:
Number of observation spells: 1
Maximal time range observed: 2014 until 2020
Temporal mode: continuous
Time unit: unknown
Suggested time increment: NA
都好。现在当我添加 vertex.spell 我得到这个错误:
dynamicNet <- networkDynamic(net,
edge.spells = edgelist %>% select(onset, terminus, tail, head),
vertex.spells = nodelist %>% select(onset, terminus, vertex.id) %>%
mutate(vertex.id = as.numeric(vertex.id)))
Error in networkDynamic(net, edge.spells = edgelist %>% select(onset, :
vertex.spells requires the vertex.id column to be numeric
这很奇怪,因为我明确指出 vertex.id 是数字!显然,我在某个地方填满了格式,但在哪里并不明显。任何帮助,将不胜感激。