Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have some data that encodes locations in certain countries, such as the US and China, that I would like to map. The data includes location name in Latin, extended Latin and other scripts (Japanese, Thai etc), location latitude, location longitude and some categories.

Ultimately I would like to be able to show this data on a map with administrative boundaries (roughly state/province level) and/or conurbation overlay. Likely output would be colour PNG images for use on the web.

I thought about using R (my main tool for data manipulation) to do a trial run with some of the US data but immediately stepped into a welter of jargon concerning shapefiles, attributes and the problem of trying to make a decision at least 3 different GIS packages for R. There are so many tools and moving parts out there that I am having difficulty seeing the forest for the trees.

Q. Can anybody provide a brief step-by-step summary (or a minimal example) of how I should go about mapping such data using R and some qualitative feedback on which R tools would be the most suited to me needs?

An example of my data, expressed in R code, would look something like this:

locname <- ("Shanghai Stock Exchange")
loclocalname <- c("上海证券交易所")
lat <- c(31.236259)
long <- c(121.511299)

mydf <- data.frame(locname, loclocalname, lat, long)
mydf$latlong <- paste(mydf$lat, mydf$long, sep = ",")
str(mydf)
share|improve this question

1 Answer 1

up vote 8 down vote accepted

Getting into mapping in R can be daunting - I had the same experience when I first tried it (too many packages and the help index seems to be written about two levels higher than I could (can?) understand! It is very rewarding once you get into it, though - but R is not always the best tool for the job, and often not the fastest.

There are a number of tutorials for the elements of mapping in R, including this brief one from Stackoverflow, and an excellent example of how to build shapefiles from gis.stackexchange. Both excellent reading.

In brief: the packages "maptools", "sp" and "mapdata" are your friends here:

require(sp) # the classes and methods that make up spatial ops in R
require(maptools) # tools for reading and manipulating spatial objects
require(mapdata) # includes good vector maps of world political boundaries.

Loading and plotting spatial data is really simple:

# Load a shapefile and display it
shape <- readShapePoly("example.shp")
plot(shape)

You can coerce your example data into a SpatialPointsDataFrame:

coordinates(mydf) <- ~ long + lat   # set x/y for dataframe

Use 'mapdata' for a world (or country) basemap:

map('worldHires')

And plot your data on the map:

points(mydf)
share|improve this answer
    
Thank you, this is a useful start for me. I have managed to download a shapefile for China from GADM and have read it into R, fortified it and am trying to plot with ggplot. Not doing too well so far but all part of the learning process! –  SlowLearner Mar 15 '12 at 5:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.