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
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()