使用 igraph 在 R 中的网络图上不显示特征

Features do not show on Network plot in R using igraph

我制作了一个包含 44 个特征的网络图,但特征的名称没有显示在我的网络图中。当我 运行 我的代码时,此错误显示:

Error in symbols(x = coords[, 1], y = coords[, 2], bg = vertex.color,  : 

无效的符号参数

我试过这个:,但没有任何效果。

有谁知道我应该改变什么?这是我的代码:

co <- filter(data) %>%
select(-q, -ID) %>%
  cor()

library(igraph)
g <- graph.adjacency(co,
                            weighted = TRUE,
                            diag = FALSE,
                            mode = "upper")

cut.off_b <- mean(E(g)$weight)

g_2 <- delete_edges(g, E(g)[weight < cut.off_b])

c_g_2 <- cluster_fast_greedy(g_2) 

plot(c_g_2, g_2,
     vertex.size = colSums(co) * 10,
     vertex.frame.color = NA, 
     vertex.label.color = "black", 
     vertex.label.cex = 0.8,
     edge.width = E(g_2)$weight * 15,
     layout = layout_with_fr(g_2),
     main = "Network")

dput(co):

 structure(c(1, .07977915371083, 0.152143694525588, -0.0218189826329971, 0.0485372722131193, 0.000923129223941082, -0.0222534655849573, 516, 1, -0.205361264538372, -0.149616273645181, 0.241437784766734, -0.140457111733162, 0.52697977722007, 0.588437224079489, -0.00263277091969263, 0.22151603150994, 0.245933601749799, 0.0485372722131193, -0.205361264538372, 1, 0.409240797220096, -0.444516191462303, -0.0553258405959017, 0.224169841776048, 0.286458842414816, -0.00708372057991018, 0.175543278780438, 0.190122437013223, 0.000923129223941082, -0.149616273645181, 0.409240797220096, 1 

这是我的情节:

我想你可以试试 abs(colSums(co)*10) for vertex.size in plot,因为它应该总是正值。例子如下

plot(
  c_g_2, g_2,
  vertex.size = abs(colSums(co) * 10),
  vertex.frame.color = NA,
  vertex.label.color = "black",
  vertex.label.cex = 0.8,
  edge.width = E(g_2)$weight,
  layout = layout_with_fr(g_2),
  main = "Network"
)

这给

虚拟数据

co <- cor(mtcars)