set.seed(10)
library(igraph)
# Generating graph and setting initial layout
g <- sample_gnp(100, 0.05)
layout <- layout_with_fr(g)
# Plotting original graph, maintaining fixed scale so expansion is clear
plot(layout, main="Original Graph", xlab="", ylab="", xlim=c(-20, 15), ylim=c(-20, 15))
# Expanding node positions
layout_expanded <- scale_node_positions(layout, 2)
# Plotting expanded graph, maintaining fixed scale so expansion is clear
plot(layout_expanded, main="Expanded Graph", xlab="", ylab="", xlim=c(-20, 15), ylim=c(-20, 15))
# Contract node positions
layout_cont <- scale_node_positions(layout, 0.8)
# Plotting contracted graph, maintaining fixed scale so transformation is clear
plot(layout_cont, main="Contracted Graph", xlab="", ylab="", xlim=c(-20, 15), ylim=c(-20, 15))
# Note that igraph plots like below make it difficult to see the transformation,
# because they are autoscaled.
# plot(g, layout = layout_expanded)
# The change is easy to see in scaled plots, as shown.
Run the code above in your browser using DataLab