1

我有以下数据集和以下脚本:

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.edgecountnetwork-Package但是我怎样才能把它应用到我的问题上呢?

4

1 回答 1

1

mixingmatrixfrom 函数可以network解决问题。它显示了组内和组之间的联系数量,了解同质性和混合性。

> mixingmatrix(net, "group")
       To
From    A B C D Total
  A     3 2 1 1     7
  B     3 0 1 0     4
  C     1 1 0 0     2
  D     0 0 1 0     1
  Total 7 3 3 1    14
于 2017-07-14T13:03:39.573 回答