Timo Timo - 1 year ago 108
R Question

Plotting directed multigraphs in R

I've never used any graph plotting package in R, I'm familiar with basic plotting commands and with

package. What I've found (but not tried out yet) are
packages. So I'd like to ask you, which package has simplest learning curve and satisfies following requirements:

  • Has simple layout engines (spring layout, random, ...)

  • Tries to draw multiple edges between two vertices so that they would not overlap. As a bonus it would be nice to being able to adjust this.

  • Can draw loops.

  • Vertex and edge labels, vertex and edge size and color are adjustable.

  • (No need for any of the graph algorithms like link analysis, shortest path, max flow etc, but nice, if present)

chl chl
Answer Source

The igraph package seems to fulfill your requirements, with the tkplot() function helping adjusting the final layout if needed.

Here is an example of use:

s <- cbind(A=sample(letters[1:4], 100, replace=TRUE),
           B=sample(letters[1:2], 100, replace=TRUE))
s.tab <- table(s[,1], s[,2])
s.g <- graph.incidence(s.tab, weighted=T)
plot(s.g, layout=layout.circle, 
     edge.width=c(s.tab)/3, vertex.size=20, 
     vertex.label.cex=3, vertex.label.color="white")

enter image description here

With the interactive display (there's a possibility of using rgl for 3D display), it looks like (I have slightly moved one vertex afterwards):

tkplot(s.g, layout=layout.circle, vertex.color=c(rep("red",4),rep("blue",2)))

enter image description here

Finally, you can even export you graph into most common format, like dot for graphviz.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download