3

I am wondering if there is a geo-layout to plot the network in igraph as the geo-layout in gephi. If not, how can I plot my nodes according to their latitude and longitude?

https://gephi.org/2010/map-geocoded-data-with-gephi/ is the web page for that layout. [I don't think it does great circles, but it has a small choice of projections]

Spacedman
  • 92,590
  • 12
  • 140
  • 224
Seen
  • 4,054
  • 4
  • 37
  • 46

1 Answers1

4

You'll need to convert your latitude and longitude to numeric coordinates (see e.g. this question, and simply use a two-column matrix with the coordinates as the layout argument of plot.igraph().

Community
  • 1
  • 1
Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • That'll work nicely for a small part of the globe, especially if you convert your lat-long to something cartesian in your area. A global view would be nice to have, especially if the edges were drawn as great circles... – Spacedman Sep 07 '12 at 07:26
  • There are curved edges in igraph, see `curved` in `?igraph.plotting`, but they are very simple, a bezier with a single control point and a single parameter. That is probably not enough to draw the edges as great circles. – Gabor Csardi Sep 07 '12 at 18:00
  • I have added a bug report for more flexible curved edges in igraph: https://bugs.launchpad.net/igraph/+bug/1047564 FYI. – Gabor Csardi Sep 07 '12 at 21:00
  • It would be fairly trivial to plot the points at the given x,y coordinates and then use one of the great circle drawing functions to connect connected nodes. No need to use an igraph layout function since the actual layout (ie positioning, which is 99% of what a layout functin has to do) is done. – Spacedman Sep 08 '12 at 07:06
  • If you give vertexes $x and $y attributes then plot(graph) displays the points in that layout. BUT (annoyingly) it scales the axes to be +/-1 which means you can't overlay anything else! Fix, Gabor? [Also, poss bug in output="both" in get.shortest.paths because of the x=x+1 fixes...] – Spacedman Sep 08 '12 at 23:29
  • 1
    As for the scaling, give `rescale=FALSE` to `plot()`. As for `get.shortest.path()`, yep, that's a bug, I'll fix it. In the meanwhile you can call with `vpath` and `epath`, but you probably already figured that out. – Gabor Csardi Sep 09 '12 at 00:21
  • rescale=FALSE plots the vertexes in their x and y attribute locations but still sets the plot window up to be (-1,1)! So if my x,y coords are on (10,11) I don't see anything! – Spacedman Sep 09 '12 at 09:17
  • Yes, but those you can set via `xlim` and `ylim`, as usual. You are right that when `rescale` is `FALSE`, then we could have a better default... Btw. all the plotting parameters are in `?plot.igraph` and `?igraph.plotting`. – Gabor Csardi Sep 09 '12 at 11:28
  • @GaborCsardi Thank you very much for your answer! I really appreciate your development work on igraph. – Seen Sep 10 '12 at 01:35