Reputation: 197
I use igraph R to visualize chemical compounds. In this approach, nodes correspond to atoms and edges correspond to bonds between atoms. Such represented chemical molecule is known as a molecular graph or H-depleted graphs. For instance, to represent 2-methylbutane, 2mb for short, (simple organic molecule whose carbon skeleton consists of five atoms) I use the following R code:
molecular.graph.2mb = graph.formula(1-2,2-3,3-4,2-5)
To visualize this molecular graph I use as a layout the following matrix m:
m = matrix(c(1,0,2,0,3,0,4,0,2,1), nrow=5, byrow=TRUE).
This matrix contains coordinates of vertices of my graph. Then I plot this graph:
plot(molecular.graph.2mb, layout=m).
I obtain the graph where the geometrical distance between the vertices 2 and 5 is larger than between v1 and v2, v2 and v3 as well as v3 and v4.
My question is: How to force igraph R to plot the graph where all geometrical distances will be equal?
Upvotes: 1
Views: 255
Reputation: 37641
The main trick to doing this is to set the parameter rescale=FALSE
and adjust the xlim
. Doing that alone made the nodes very small so I needed to adjust the node size as well. I think this is what you are looking for.
library(igraph)
## Your graph
molecular.graph.2mb = graph.formula(1-2,2-3,3-4,2-5)
m = matrix(c(1,0,2,0,3,0,4,0,2,1), nrow=5, byrow=TRUE)
## Modified plot
plot(molecular.graph.2mb, layout=m, rescale=FALSE,
vertex.size=30, xlim=c(0.5,4.5))
Upvotes: 1