As Sasha Epscamp mentioned, if your data is not perfect, you cannot draw a graph that does not violate some triangular inequalities. However, there are methods called Multidimensional Scaling (MDS) , aimed at minimizing such violations.
One implementation in R is equal to cmdscale
from the stats
package. I would recommend the example below ?cmdscale
:
> require(graphics) > > loc <- cmdscale(eurodist) > x <- loc[,1] > y <- -loc[,2] > plot(x, y, type="n", xlab="", ylab="", main="cmdscale(eurodist)") > text(x, y, rownames(loc), cex=0.8)
Of course, you can draw x
and y
using any graphic packages (you specifically asked a question about igraph
).
Finally, I’m sure that you will find many other implementations if you look for “multidimensional scaling” or “MDS”. Good luck.
source share