views:

69

answers:

1

Hi all,

I created a network graph from data on flows between US states. For each vertex, I have the lat/long of the state.

I am hoping to recreate a network kind of graph that shows the edges, except that I set the location of each vertex to be their geographic position and have a state boundary map in the background.

I am using to igraph to create my network. There have been some cool mapping examples in ggplot2, so I am wondering if that is an option. I believe I have seen similar options using Pajek, but I am hoping to stay within R.

maps in ggplot2

Any ideas/insight would be appreciated.

  • Brock
+4  A: 

You have multiple packages dealing with maps. The most easy is maps, which gives you the states map. You can plot the vertices over using the coordinates.

map("state")
points(longitute,latitude)

These plots can be manipulated and added to using the base tools, keeping in mind the x axis is the longitude and the y axis is the latitude. edges can be plotted using the segments() function.

In ggplot2 just use the map_data() function, which gives you the shape-data of the map, and the geom_polygon() to add it to the graph in whatever form you want. Again, you can add the vertices and edges using the coordinates with the appropriate ggplot2 function geom_point() and geom_segment(). The code you link at shows you how, or otherwise look at this for an example.

Next to that, you can take a look at the packages maptools, which offers more functionality and, mapproj, which allows for different projections of the same map. You can use these packages as well to calculate geographical distances in a coordinate system.

mapdata contains more databases, and covers basically the whole world. You can work with coordinates pretty nicely.

Joris Meys