O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Perform the following steps to use force layout:

  1. Load the data file:
> library(igraph)> load("retweet-graph.Rdata") 
  1. Now we will plot the reTweet graph data using Force Layout:
> plot(reTweets_graph, layout=layout.fruchterman.reingold,     vertex.color="blue",     vertex.size=(degree(reTweets_graph, mode = "in")), #sized by in-degree centrality     vertex.label = NA,     edge.arrow.size=0.8,     edge.arrow.width=0.5,     edge.width=edge_attr(reTweets_graph)$n/10, #sized by edge weight     edge.color=hsv(h=.95, s=1, v=.7, alpha=0.5))title("Retweet Network using Force Layout", cex.main=1, col.main="black")

The following plot illustrates the force directed algorithm layout:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required