gpt4 book ai didi

具有相同颜色(特征)的R igraph簇节点

转载 作者:行者123 更新时间:2023-12-04 01:17:12 25 4
gpt4 key购买 nike

# example data
library(igraph)
links <- cbind.data.frame(from = rep("A", 6),
to = LETTERS[1:6],
weight = rep((1:3), each =2))

nodes <- nodes <- cbind.data.frame(id = LETTERS[1:6],
feature = rep((1:3), each =2))

net <- graph_from_data_frame(d = links, vertices = nodes, directed = T)
V(net)$color <- V(net)$feature
plot(net, vertex.size=30, edge.arrow.size = 0)

这是我得到的: enter image description here

我想要的是将相同颜色的节点聚集在一起,类似于下图所示。我该怎么做?

enter image description here

最佳答案

也许 plot 中的选项 mark.groups 会有所帮助

plot(net,mark.groups = split(V(net)$name,V(net)$color))

给出

enter image description here

关于具有相同颜色(特征)的R igraph簇节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63149080/

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