6.1 Polygon Maps
The simplest approach to mapping is using geom_polygon(). This forms bounderies around regions.
library(ggplot2)
mi_counties <- map_data("county", "michigan") %>%
select(lon = long, lat, group, id = subregion)
head(mi_counties)## lon lat group id
## 1 -83.88675 44.85686 1 alcona
## 2 -83.36536 44.86832 1 alcona
## 3 -83.36536 44.86832 1 alcona
## 4 -83.33098 44.83968 1 alcona
## 5 -83.30806 44.80530 1 alcona
## 6 -83.30233 44.77665 1 alcona
In this data set we have four variables:
- lat: Latitude of the vertex (as measured by horizontal paths)
- long: Longitude of the vertex (as measured by vertical paths)
- id: name of the region
- group: unique identifier for contiguous areas within a region
-1.png)
ggplot(mi_counties, aes(lon, lat, group = group)) +
geom_polygon(fill = "white", colour = "grey50") +
coord_quickmap()-2.png)
In this plot, coord_quickmap() is used to adjust the axes to ensure longitude and latitude are rendered on the same scale
For a more advanced use of ggplot2 for mapping, we’ll see the use of geom_sf() and coord_sf() to handle spatial data specified in simple features format.