我想使用 GGally 或 ggnetwork 绘制一个网络对象,并且我希望能够生成一个布局,其中节点按顶点属性分组。我花了一些时间寻找一种方法来做到这一点,但还没有弄清楚。是否可以按属性在布局中对节点进行分组,使得所有具有属性“a”的节点都在一个集群中,具有属性“b”的节点都在一个集群中,等等?
提前致谢。
这里有两个例子:
library (GGally)
library (ggnetwork)
library (ggplot2)
library (sna)
library (network)
#make a random network with some vertex attributes
abc<-as.network(rgraph(20,1))
abc %v% "kinds" <- letters[1:3]
abc %v% "model" <- LETTERS[12:18]
#plot the network using ggnet2 in library (GGally)
#I want to somehow group the nodes together by a vertex attribute.
#Here I have tried to group nodes by "kinds." How to do this??
ggnet2(abc,
size="degree", size.cut=3,
color = "kinds",
group = "kinds")
#and here is an example using library (ggnetwork)
#set degree as an attribute to call in ggnetwork.
#I could not figure out another way to set size = degree without first
#passing it as a vertex attribute.
abc %v% "deg_4ggnet"<-degree(abc)
abc2<-ggnetwork(abc)
ggplot(abc2, aes(x = x, y = y, xend = xend, yend = yend))+
geom_edges(color = "black") +
geom_nodes(aes(color = kinds, size = deg_4ggnet)) +
theme_blank()
#How to group by vertex attribute "kinds"???