微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 igraph 在 R 中的网络图上不显示功能

如何解决使用 igraph 在 R 中的网络图上不显示功能

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

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

无效的交易品种参数

我试过这个:Unable to plot a network on igraph,但没有任何效果

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

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.409240797220096,-0.444516191462303,-0.0553258405959017,0.224169841776048,0.286458842414816,-0.00708372057991018,0.175543278780438,0.190122437013223,1 

这是我的情节:

enter image description here

解决方法

我想您可以在 data 中为 abs(colSums(co)*10) 尝试 vertex.size,因为它应该始终为正值。一个例子如下

plot

这给 enter image description here

虚拟数据

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"
)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。