[英]How to draw social network graph with R more clearly?
i'm now using lesmis.gml to do network analysis homework.我现在正在使用 lesmis.gml 做网络分析作业。 I can't adjust graph node's distance: there's more than 70 nodes and the nodes are too close.
我无法调整图形节点的距离:有超过 70 个节点并且节点太近。 graph is variable g and g2.
图是变量 g 和 g2。 graph looks weird like this.(image) here's my code using R. I tried to use Gephi, but my laptop doesn't run it well.
图看起来很奇怪。(图片)这是我使用 R 的代码。我尝试使用 Gephi,但我的笔记本电脑不能很好地运行它。 It shuts off.
它关闭。
install.packages('igraph')
install.packages('statnet')
library('igraph')
library('statnet')
g<-read.graph("lesmis.gml", format=c("gml"))
g
graph.density(g)
igraph::degree(g,mode="out")
plot(g)
vcount(g)
centralization.degree(g)
V(g)$size<-igraph::degree(g)*5
plot(g)
clo<-igraph::closeness(g)
clo
clo.score<-round((clo-min(clo))*length(clo)/max(clo))+1
clo.colors<-rev(heat.colors(max(clo.score)))
V(g)$color<-clo.colors[clo.score]
plot(g)
btw<-igraph::betweenness(g)
btw
btw.score<-round(btw)+1
btw.score
btw.colors<-rev(heat.colors(max(btw.score)))
V(g)$color<-btw.colors[btw.score]
plot(g)
clusters(g)
clusters(g)$csize
cliques(g)
sapply(cliques(g), length)
largest_cliques(g)
cliques(g)
sapply(cliques(g),length)
a<-largest_cliques(g)
a
clique1<-a[[1]]
g2<-induced.subgraph(graph=g,vids=clique1)
plot(g2)
vcol<-rep("grey80",vcount(g))
vcol[unlist(largest_cliques(g))]<-"gold"
plot(as.undirected(g),vertex.lavel=V(g)$name, vertex.color=vcol)
windows()
I have two suggestions.我有两个建议。 Before presenting them, I will set up the basics so that what I do is (mostly) repeatable.
在介绍它们之前,我将设置基础知识,以便我所做的(大部分)可重复。 This is just a streamlined version of what you had in your code, with a change to the vertex size as you had it.
这只是您代码中的简化版本,并更改了您拥有的顶点大小。
library(igraph)
g<-read.graph("temp/lesmis.gml", format=c("gml"))
V(g)$size<-igraph::degree(g)/2
btw<-igraph::betweenness(g)
btw.score<-round(btw)+1
btw.colors<-rev(heat.colors(max(btw.score)))
V(g)$color<-btw.colors[btw.score]
I think that this is what @nhl was suggesting.我认为这就是@nhl 的建议。 There are quite a few layout functions in igraph.
igraph 中有不少布局功能。 Just try a bunch of them and see what looks good.
只需尝试一堆,看看什么看起来不错。 I kind of liked the large graph layout.
我有点喜欢大图布局。
set.seed(1234)设置种子(1234)
LO_LGL = layout_with_lgl(g) LO_LGL = layout_with_lgl(g)
plot(as.undirected(g), layout=LO_LGL, margin=c(-0.25,-0.25))情节(as.undirected(g),布局= LO_LGL,边距= c(-0.25,-0.25))
tkplot
which will allow you to select nodes and move them around to make the graph more readable.tkplot
这将允许你选择节点并移动它们以使图形更具可读性。 tkplot(as.undirected(g), layout=LO_LGL)
I used the previous layout as a starting place and adjusted the vertices by hand to make the graph clearer.我以之前的布局为起点,手动调整顶点,使图形更清晰。 It is not perfect, but you can see some of the communities.
它并不完美,但您可以看到一些社区。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.