gpt4 book ai didi

javascript - 在 VisNetwork Igraph 中为顶点添加颜色

转载 作者:太空宇宙 更新时间:2023-11-04 16:30:08 25 4
gpt4 key购买 nike

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

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

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 的“group”属性,默认情况下通知节点颜色。利用您 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com