# Create a random graph
library(igraph)
g <- sample_gnp(100, 0.05)
# Assign non-numeric row names
V(g)$name <- paste0("node", 1:vcount(g))
# Apply ForceAtlas2 layout
pos <- layout.forceatlas2(g, linlog = TRUE, iterations = 100, scalingratio = 10)
V(g)$x = as.numeric(pos[,1])
V(g)$y = as.numeric(pos[,2])
# Plotting (preserves the exact degree of rotation)
igraph::plot.igraph(g, rescale = FALSE,
xlim = range(pos[,1]), ylim = range(pos[,2]))
Run the code above in your browser using DataLab