绘制时间网络-边缘列表所需的TRUE / FALSE值

问题描述 投票:0回答:1

我正在尝试使用以下数据绘制基本的静态网络。数据代表了一小群传染病暴发。

PHStaticEdges
tail head 
1    2    
1    3    
1    4    
2    5    
PHVertexAttributes
vertex.id name Place
1         A    House
2         B    House
3         C    Flight
4         D    Work
5         E    Flight

当我运行此代码时:

thenetwork <- network(
  PHStaticEdges,
  vertex.attr = PHVertexAttributes,
  vertex.attrnames = c("vertex.id", "name", "place"),
  directed = FALSE,
  bipartite = FALSE
)
plot(thenetwork)

我收到以下错误:

Error in if (matrix.type == "edgelist") { : 
  missing value where TRUE/FALSE needed

最终,我想创建一个显示随时间变化的分支边缘的时间图,但是我需要首先正确获取静态图!我要去哪里错了?

r graph social-networking
1个回答
0
投票

也许您的vertex_list有某些因素?下面的代码就像一个魅力一样工作:

Phedges <- data.frame(from = c(1,1,1,2) , to= c(2,3,4,5) , stringsAsFactors = F)
#don't want factor in the edges-list

phvertex <- data.frame(stringsAsFactors = F, 
     vertex.id = 1:5,
     name = c("A", "B", "C", "D", "E"),
     type = c( 'House', 'House', 'Flight', 'Work', 'Flight')
                       )
#don't want factor in the nodes-list

thenetwork <- network::network(
   Phedges,
   vertex.attr = phvertex,
   vertex.attrnames = c("vertex.id", "name", "type"),
    directed = FALSE,
     bipartite = FALSE )

 # then you plot if you want = the network is ok
 plot(thenetwork)
 ggraph::ggraph(thenetwork) + ggraph::geom_node_point() + ggraph::geom_edge_link() + 
 ggplot2::theme_void() # assuming you have these cool packages.

PS:祝您好运networkDynamic::activate.edges或动态节点。 我认为,使用tidyverse和edges-list(以便选择数据并创建网络的多个“切片”,进行计算分析并保持对同一数据的不同“时间版本”的理解)。用tidyverse过滤边缘列表比过滤这些时态网络包更容易。

© www.soinside.com 2019 - 2024. All rights reserved.