这是一个更普遍的问题:VisNetwork from IGraph - Can't Implement Cluster Colors to Vertices

我有一张已转换为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)


谢谢

(如果您想获得可复制的代码,请参考我在文章顶部提到的链接。)

最佳答案

您可以将其添加为igraph的“组”属性,该属性默认情况下通知节点着色。利用other post中的代码:

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

关于javascript - 在VisNetwork Igraph中为顶点添加颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39884376/

10-11 17:48