Graphics Reference
In-Depth Information
Creating a Map from a Shapefile
Problem
You want to create a geographical map from an Esri shapefile.
Solution
Load the shapefile using readShapePoly() from the maptools package, convert it to a data
frame with fortify() , then plot it ( Figure 13-39 ):
library(maptools)
# Load the shapefile and convert to a data frame
taiwan_shp <- readShapePoly( "TWN_adm/TWN_adm2.shp" )
taiwan_map <- fortify(taiwan_shp)
ggplot(taiwan_map, aes(x = long, y = lat, group = group)) + geom_path()
Search WWH ::




Custom Search