Using the sp package to plot geographic data
The sp
package has the necessary features to store and plot geographic data. In this recipe, we will use the sp
package to plot imported shape files.
Getting ready
Install the packages rgdal
and sp
. If you have issues installing the rgdal
package on Mac or Linux, refer to the earlier recipe for details.
Copy the following files to your R working directory:
ne_50m_admin_0_countries.shp
ne_50m_admin_0_countries.prj
ne_50m_admin_0_countries.shx
ne_50m_admin_0_countries.VERSION.txt
ne_50m_airports.shp
ne_50m_airports.prj
ne_50m_airports.shx
ne_50m_airports.VERSION.txt
We obtained these files from http://www.naturalearthdata.com/.
How to do it...
To plot geographic data using the sp
package, follow these steps:
- Load the ...
Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.