0

i'm now using lesmis.gml to do network analysis homework. I can't adjust graph node's distance: there's more than 70 nodes and the nodes are too close. graph is variable g and 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. 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()
MS.K
  • 25
  • 6
  • I don't have an answer, but there are some cool network analysis viz packages out there like `ggraph` and `ggnet`. Those may be helpful – Evan O. May 28 '18 at 02:27
  • Have you tried to change layout? Or, you can check this [question](https://stackoverflow.com/questions/39290909/igraph-resolving-tight-overlapping-nodes). – s__ May 28 '18 at 06:47
  • Not an answer to your question, but in your `plot` statement, you have `vertex.lavel=V(g)$name`. Should that be `vertex.label` ? – G5W May 28 '18 at 23:20

1 Answers1

2

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]
  1. I think that this is what @nhl was suggesting. There are quite a few layout functions in igraph. Just try a bunch of them and see what looks good. I kind of liked the large graph layout.

    set.seed(1234)
    LO_LGL = layout_with_lgl(g)
    plot(as.undirected(g), layout=LO_LGL, margin=c(-0.25,-0.25))

LesMis - just LGL

  1. Once you get something that is pretty close, you might try using tkplot which will allow you to select nodes and move them around to make the graph more readable.

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.

LesMis - tkplot

G5W
  • 36,531
  • 10
  • 47
  • 80