在 VisNetwork Igraph 中为顶点添加颜色

Adding Color to Vertex in VisNetwork Igraph

这是一个更笼统的问题:

我有一个已转换为 visNetwork 的 igraph:

library(visNetwork)
visIgraph(igraph, idToLabel = TRUE, layout = "layout_nicely")%>%
visNodes(size = 10) %>%
visOptions(highlightNearest = TRUE, 
     nodesIdSelection = TRUE)

我有一个颜色列表,对应于我想为图形着色的节点:

颜色如下:

c("#80FF00FF" "#FF0000FF" "#FF0000FF" "#00FFFFFF" "#FF0000FF" "#8000FFFF" "#FF0000FF" "#FF0000FF" "#FF0000FF" "#FF0000FF")

如何将这些颜色添加到 visNetwork 的节点?

如果我要这样做,它在正常情节中有效,但在 visNetwork 中无效:

V(igraph)$color <- c("#80FF00FF" "#FF0000FF" "#FF0000FF" "#00FFFFFF" "#FF0000FF" "#8000FFFF" "#FF0000FF" "#FF0000FF" "#FF0000FF" "#FF0000FF")
plot(igraph)

谢谢

(如果你想获得可重现的代码,请参考我在 post 顶部提到的 link。)

您可以将其添加为 igraph 的 "group" 属性,默认情况下通知节点着色。从您的 中提取代码:

col = c("#80FF00FF", "#FF0000FF", "#FF0000FF", "#00FFFFFF",
          "#FF0000FF", "#8000FFFF", "#FF0000FF", "#FF0000FF",
          "#FF0000FF", "#FF0000FF")
i96e <- set.vertex.attribute(i96e, name = "group",value = col)
visIgraph(i96e, idToLabel = TRUE, layout = "layout_nicely")