我有以下数据集和以下脚本:
library(GGally)
library(ggnet)
library(network)
library(sna)
library(ggplot2)
# edgelist
e <- data.frame(sender = c(1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5),
receiver = c(2, 3, 4, 5, 1, 3, 1, 1, 2, 2, 4, 3, 2, 4))
# information about the nodes (vertices)
v <- data.frame(actors = c(1, 2, 3, 4, 5),
groups = c("A", "A", "B", "C", "D"))
net <- network(e, directed = TRUE)
x = data.frame(actors = network.vertex.names(net))
x = merge(x, v, by = "actors", sort = FALSE)$groups
net %v% "group" = as.character(x)
y = RColorBrewer::brewer.pal(9, "Set1")[ c(3, 1, 9, 6, 8) ]
names(y) = levels(x)
ggnet2(net, color = "group", palette = y, alpha = 0.75, size = 4, edge.alpha = 0.5, arrow.size = 8, arrow.gap = 0.01)
有没有一种简单快捷的方法来计算从一组节点(A、B、C、D)到同一组节点或另一组节点(即从 AA、AB、AC、AD、学士等)?
里面有network.edgecount
。network-Package
但是我怎样才能把它应用到我的问题上呢?