【问题标题】:Features do not show on Network plot in R using igraph使用 igraph 在 R 中的网络图上不显示特征
【发布时间】:2021-07-01 09:21:32
【问题描述】:

我制作了一个包含 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")

输入(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 

这是我的情节:

【问题讨论】:

  • dput(data)dput(co)分享您的数据
  • 你应该共享变量 co
  • 嗯,我的意思是 dput(co)
  • 你的意思是:.Dimnames = list(c("A", "B", "C", "F", "G", "H", "K", "L" ,“N”,“P”,“S”),c(“A”,“B”,“C”,“F”,“G”,“H”,“K”,“L”,“N” ", "P", "S") @ThomasIsCoding
  • 不。您可以在控制台中输入dput (co) 并将输出复制到您的帖子中。您应该共享 co 中的值

标签: r networking plot igraph


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 2021-08-30
    • 2012-03-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多