12.3 Choropleth Maps
Sometimes maps use shading of polygons to display quantitative information about a geographic unit or qualitative information about what geographical units belong to different categories of a variable. We provide an example of this here.
- We are going to add a variable to our mapping data that we want to visualize
- We
fill
the plot usinggeom_polygon
and can (optionally) indicate specific colors
<- map_data("state")
usmap $nj <- ifelse(usmap$region == "new jersey", "Cannot turn left",
usmap"Can turn left")
$nj <- as.factor(usmap$nj)
usmap
ggplot()+
## Note the fill= nj
geom_polygon(data=usmap, aes(x=long, y=lat, group=group, fill=nj))+
## we can indicate colors for each category of the nj variable
scale_fill_manual(values = c("gray", "red3"), name="Left Turns")+
theme_void() +
ggtitle("Geography of Left Turns")+
coord_quickmap()