[R] Projecting data on a world map using long/lat

mathijsdevaan mathijsdevaan at gmail.com
Fri Dec 10 17:53:46 CET 2010


Thanks for the suggestions, but I am not there yet (I'm a real novice). In
the code provided by Patrick (see below), I changed the shape input (from
sids to world) which I downloaded here:
http://thematicmapping.org/downloads/world_borders.php. As a result I also
need to change the "CNTY_ID" and "id" in the code, but I have no idea what
to put there. Could you please help me? Thanks!

Mathijs

library(maptools)
library(ggplot2)
gpclibPermit()

myshp<- readShapeSpatial(system.file("shapes/sids.shp",
package="maptools"))

## see licence, not GPL
myshp.points<- fortify.SpatialPolygonsDataFrame(myshp,
region="CNTY_ID")

shpm<- merge(myshp.points, myshp, by.x="id", by.y="CNTY_ID")

head(shpm)

p <- ggplot(shpm, aes(long, lat, group=group, fill=NWBIR74))
p <- p + geom_polygon() + geom_path(color="white") + coord_equal()

## Add some locations
cities <- read.table(textConnection("
long        lat      city      val
-78.644722 35.818889  Raleigh   323
-80.843333 35.226944  Charlotte  510
-82.555833 35.58      Asheville    400"), header = TRUE)

p <- p + geom_point(aes( fill=NULL, group = NULL, size=val),
         data = cities, color= 'black')
p
-- 
View this message in context: http://r.789695.n4.nabble.com/Projecting-data-on-a-world-map-using-long-lat-tp3081298p3082305.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list