cluster_edge_betweenness 在来自命名 one-mode 矩阵的 igraph 中
cluster_edge_betweenness in igraph from named one-mode matrix
我想使用 igraph 函数 cluster_edge_betweenness
聚类一个 one-mode 网络矩阵进行绘图,据我所知,这是可行的:
library("igraph")
adjm <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.9,0.1)), nc=10)
colnames(adjm) <- LETTERS[1:10]
row.names(adjm) <- LETTERS[1:10]
g <- graph_from_adjacency_matrix(adjm,
mode = "undirected",
weighted = "weight",
diag = TRUE,
add.colnames = NULL)
c <- cluster_edge_betweenness(g,
weights = igraph::E(g)$weight,
edge.betweenness = TRUE,
merges = TRUE,
bridges = TRUE,
modularity = FALSE,
membership = FALSE)
但是,这给了我错误:
Error in names(res) <- communities$names :
'names' attribute [10] must be the same length as the vector [0]
这很奇怪,因为在 add.colnames = NULL
时应该分配名称,至少如果我正确理解帮助的话:
add.colnames
Character scalar, whether to add the column names as
vertex attributes. If it is ‘NULL’ (the default) then, if present,
column names are added as vertex attribute ‘name’.
然后,更奇怪的是,尽管有错误(不是警告!)cluster_edge_betweenness
实际上生成了我想要的对象并且我可以绘制它:
hc <- as.hclust(c, hang = -1, use.modularity = FALSE)
plot(hc)
这是怎么回事?我应该在他们的 GitHub 页面上提出问题还是我误解了什么?
注意:使用 igraph 1.2.1 测试。
函数中抛出错误membership
:
function (communities)
{
if (!is.null(communities$membership)) {
res <- communities$membership
}
else if (!is.null(communities$merges) && !is.null(communities$modularity)) {
res <- community.to.membership2(communities$merges, communities$vcount,
which.max(communities$modularity))
}
else {
stop("Cannot calculate community membership")
}
if (igraph_opt("add.vertex.names") && !is.null(communities$names)) {
names(res) <- communities$names
}
class(res) <- "membership"
res
}
问题似乎是 communities$membership
是 numeric(0)
。因此 res
也变成了 numeric(0)
并且,因为
communities$names
# [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
我们在 names(res) <- communities$names
中得到了错误。
因此,它看起来像是来自某个地方的错误,正如我评论的那样,快速修复是在调用 cluster_edge_betweenness
.
时设置 membership = TRUE
我想使用 igraph 函数 cluster_edge_betweenness
聚类一个 one-mode 网络矩阵进行绘图,据我所知,这是可行的:
library("igraph")
adjm <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.9,0.1)), nc=10)
colnames(adjm) <- LETTERS[1:10]
row.names(adjm) <- LETTERS[1:10]
g <- graph_from_adjacency_matrix(adjm,
mode = "undirected",
weighted = "weight",
diag = TRUE,
add.colnames = NULL)
c <- cluster_edge_betweenness(g,
weights = igraph::E(g)$weight,
edge.betweenness = TRUE,
merges = TRUE,
bridges = TRUE,
modularity = FALSE,
membership = FALSE)
但是,这给了我错误:
Error in names(res) <- communities$names :
'names' attribute [10] must be the same length as the vector [0]
这很奇怪,因为在 add.colnames = NULL
时应该分配名称,至少如果我正确理解帮助的话:
add.colnames
Character scalar, whether to add the column names as vertex attributes. If it is ‘NULL’ (the default) then, if present, column names are added as vertex attribute ‘name’.
然后,更奇怪的是,尽管有错误(不是警告!)cluster_edge_betweenness
实际上生成了我想要的对象并且我可以绘制它:
hc <- as.hclust(c, hang = -1, use.modularity = FALSE)
plot(hc)
这是怎么回事?我应该在他们的 GitHub 页面上提出问题还是我误解了什么?
注意:使用 igraph 1.2.1 测试。
函数中抛出错误membership
:
function (communities)
{
if (!is.null(communities$membership)) {
res <- communities$membership
}
else if (!is.null(communities$merges) && !is.null(communities$modularity)) {
res <- community.to.membership2(communities$merges, communities$vcount,
which.max(communities$modularity))
}
else {
stop("Cannot calculate community membership")
}
if (igraph_opt("add.vertex.names") && !is.null(communities$names)) {
names(res) <- communities$names
}
class(res) <- "membership"
res
}
问题似乎是 communities$membership
是 numeric(0)
。因此 res
也变成了 numeric(0)
并且,因为
communities$names
# [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J"
我们在 names(res) <- communities$names
中得到了错误。
因此,它看起来像是来自某个地方的错误,正如我评论的那样,快速修复是在调用 cluster_edge_betweenness
.
membership = TRUE