13.19 Creating a Map from a Shapefile

13.19.1 Problem

You want to create a geographical map from an Esri shapefile.

13.19.3 Discussion

Esri shapefiles are a common format for map data. The st_read() function reads a shape file and returns a sf object, which will also have other useful columns. Here’s a look at the contents of the object.

The sf object is a special kind of data frame, with 22 rows and 12 columns. Each row corresponds to one feature, and each column has some data about each feature. One of the columns is the geometry for each feature. This is a list-column – a special type of column where each of the 22 elements contains one or more matrices of numbers representing the shape of the feature.

Columns in the data can be mapped to aesthetics like fill. For example, we can mapp the ENGTYPE_2 column to fill, as shown in Figure 13.40:

With a column mapped to fill

Figure 13.40: With a column mapped to fill

13.19.4 See Also

The shapefile used in this example is not included in the gcookbook package. It and many other shapefiles are available for download at http://www.gadm.org.