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.
Any ideas/insight would be appreciated.
- Brock
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.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 thegeom_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 functiongeom_point()andgeom_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.mapdatacontains more databases, and covers basically the whole world. You can work with coordinates pretty nicely.