如何使用R package Network或类似方法基于属性值删除网络中的顶点

时间:2017-01-16 00:58:42

标签: r network-analysis

我正在尝试从矩阵构建网络,以便我可以绘制整个网络或仅顶点的子集。我一直在使用R中的网络包 并创建了一个玩具网络,我在顶点添加了两个属性:'year'和'topic'。然后我绘制网络,使主题的颜色不同。

library(network)
B = matrix(c(1, 1, 0, 1, 1,0,1,1,0,1,1,0,0,0,1,0,0,1,1,0,1,0,0,1,0), nrow=5, ncol=5)
b<-network(B)
b %v% "topic"=c("Surveillance","Inspection efficiency","Surveillance","Inspection efficiency","Surveillance")
b %v% "year"=c(2006,2006,2007,2007,2007)
ggnet2(b,node.size = 10, node.color = "topic", edge.size = 1, edge.color = "grey",palette = "Set2",label=c("1101","908","1107","601","604"),label.size = 3)`

我想要做的是绘制同一个网络,但仅针对属性'year'的值为'2006'的顶点。欢迎任何建议

1 个答案:

答案 0 :(得分:0)

使用%s%运算符设置网络。

library(network)
B = matrix(c(1, 1, 0, 1, 1,0,1,1,0,1,1,0,0,0,1,0,0,1,1,0,1,0,0,1,0), nrow=5, ncol=5)
b<-network(B)
b %v% "topic"=c("Surveillance","Inspection efficiency","Surveillance","Inspection efficiency","Surveillance")
b %v% "year"=c(2006,2006,2007,2007,2007)

b2006 <- b %s% which(b %v% "year"==2006)