Reputation: 33
I'm currently conducting some social network analysis using the `igraph' package in R, and I wanted to know if there is a way to personalize the placement of nodes in the social network.
For example, with the following toy code:
library(igraph)
edge <- cbind(c(1,1,1,2,2,3,3,3,4),c(2,3,4,3,4,1,2,4,2),c(1,1,1,1,1,1,1,1,1))
vertex <- c(1,2,3,4)
g <- graph.data.frame(edge, directed=FALSE, vertices=vertex)
plot(g)
In this case, the network is kind of small compared to the plot space. Is there a way I can increase the distance between nodes? And, additionally, is it possible to position a node in a specific place (e.g. (x,y))?
Thank you!
Upvotes: 3
Views: 911
Reputation: 1035
As in comment by @user20650 - you can pass a layout to the plot
function
plot(g, layout=mylay)
If you want to manipulate the layout, the best way is to generate some first:
mylay <- layout.auto(g)
then if you print mylay
, you will see it is just a list of pairs (usually a two column matrix, to be precise), where numbers in those pairs are coordinates of a node. So if you want to change the position of a node number X, you have to manipulate Xth pair in the layout. You also can generate the whole layout on your own. See this doc for more: http://igraph.org/r/doc/layout_.html
Upvotes: 0