4

I have a network (igraph) with the following characteristics:

>g
IGRAPH DN-- 3370 16699 --
+ attr: name (v/c), grupo (v/n), year (v/n), grupo.freq (v/n),
  grupo.perc (v/n), vertex.frame.size (v/n), color (v/c),
  vertex.frame.color (v/c), grupo (e/n), year (e/n), color (e/c)

after make clustering have the following groups:

>table(V(g)$grupo)
   1    2    8
1516 1367  487

I have interest in a view that can highlight the relationship between groups (V(g)$grupo). I used the software Gephi with the layout Force Atlas 2 to the next image: https://i.stack.imgur.com/GQxyT.png

My question is, how to have a similar result in the R?

I'm using the following code:

colbar <- rainbow(length(table(V(g)$grupo)))
V(g)$color <- colbar
E(g)$color <- colbar
V(g)$vertex.frame.color <- colbar
V(g)$vertex.frame.size <- 0.1

plot.igraph(
            g,
            layout=layout.fruchterman.reingold.grid,
            vertex.label=NA,
            vertex.size=1,
            edge.lty=1,
            edge.arrow.size=0.0000001
            )

Follow the link to download the data I used in csv or in Rdata: http://www.datafilehost.com/d/855e3e86

  • This [question](http://stackoverflow.com/questions/9876267/r-igraph-community-detection-edge-betweenness-method-count-list-members-of-e) may assist. You might be able to adapt that method to suit yours. – Rusan Kax Jan 19 '15 at 10:29

3 Answers3

5

First, get the ForceAtlas2 package.

install.packages("devtools")
if (!require("ForceAtlas2")) devtools::install_github("analyxcompany/ForceAtlas2")
library("ForceAtlas2")

Then, to render a graph g with a layout l do something like (here with all available layout parameters):

g <- erdos.renyi.game(1000, 1/1000)
l <- layout.forceatlas2(g, directed=TRUE, iterations = 100, 
                           linlog = FALSE, pos = NULL, nohubs = FALSE, 
                           k = 400, gravity=1, ks=0.1, ksmax=10, delta = 1,  
                           center=NULL, tolerance = 0.1, dim = 2,
                           plotstep=10, plotlabels=TRUE)
plot(g,layout=l)

You can provide options like vertex.size = 3, vertex.color = "red" et cetera to the plot function if you wish.

Mischa
  • 623
  • 5
  • 17
4

A code in R to produce the Force Atlas 2 layout is available now: https://github.com/adolfoalvarez/Force-Atlas-2

The layout is not yet developed as a package so you will need to source the code into R, and use the "igraph" package.

The usage for this would be:

library(igraph)
g <- graph.ring(100)
layout.forceatlas2(g, iterations=10000, plotstep=500)
2

Now the ForceAtlas2 function mentioned by @ciberalcito is implemented in an R package. Please check https://github.com/analyxcompany/ForceAtlas2

adalvarez
  • 43
  • 1
  • 4