One element of the solution is no doubt the rescale = FALSE
parameter to igraph::plot()
as I suggested in comment. OP asked why ey gets an empty plot with this? It's because the plotting area is still limited to the [-1; 1]
interval along both x and y axes. This is default of igraph::plot()
. So we need to give xlim = c(-180, 180)
and ylim = c(-90, 90)
parameters. This already gives a correct positioning. However, if our aim is to produce a figure with the map of the world, maybe it is the best to write the igraph plot onto a cairo SVG device. Then we will be able to place the map behind the graph in any SVG editor (e.g. Inkscape is a great solution), and we are still free to scale and edit the graph and the labels. For doing this, some other igraph.plotting
parameters necessary to be set, but this is already about proportions and aesthetics. Here is the code I used to produce the SVG output:
#!/usr/bin/Rscript
require(igraph)
require(Cairo)
df <- data.frame("from" = c("Bob", "Klaus", "Edith", "Liu"),
"to" = c("Edith", "Edith", "Bob", "Klaus"))
meta <- data.frame("name" = c("Bob", "Klaus", "Edith", "Liu"),
"lon" = c(-74.00714, 13.37699, 2.34120, 116.40708),
"lat" = c(40.71455, 52.51607, 48.85693, 39.90469))
g <- graph.data.frame(df, directed = TRUE, vertices = meta)
lo <- layout.norm(as.matrix(meta[,2:3]))
dpi = 1.0
Cairo(file = 'map-graph.svg', type = "svg",
units = "in",
width = 4 / dpi,
height = 2 / dpi,
dpi = dpi)
plot.igraph(g,
layout = lo,
xlim = c(-180, 180),
ylim = c(-90, 90),
rescale = FALSE,
edge.curved = TRUE,
edge.arrow.size = 10 / dpi,
edge.arrow.width = 0.5 / dpi,
vertex.label.dist = 50 / dpi,
vertex.label.degree = 90 / dpi,
vertex.size = 200 / dpi,
vertex.label.cex = 21 / dpi,
vertex.frame.color = NA,
vertex.label.color = '#FFFF00',
edge.color = '#FFFFFF',
vertex.label.family = 'sans-serif',
edge.width = 16 / dpi)
dev.off()
When the SVG produced by igraph looks fine, we can open it in Inkscape. Then import (Ctrl+i
) the map in case it is pixmap; or open if it is vector graphics (e.g. PDF, SVG). Manually scale and position the map to set the same scale as the graph in the SVG (i.e. until the points get to their right place) – for proportional scaling, hold the Ctrl
in Inkscape. Here is the result of this method:
(The map image is made available for non-commercial public use by Wikimedia Commons).
I think igraph is capable to produce figures like this, but this is not the primary aim of this software, so it has its limitations. At some point you might consider to use some Geographic Information System (GIS) software which is designed exactly to do things like this. I have no experience with those, but qgis probably worths to take a look at.