Displaying Information with Maps

In this section, we'll create a map of the US and Europe that is colored according to lat, long, and group variables. Let's begin by implementing the following steps:

  1. Install the maps package using map_data to get a data frame for the different states' information, as follows:
states_map <- map_data("state")glimpse(states_map)## Observations: 15,537## Variables: 6## $ long <dbl> -87.46201, -87.48493, -87.52503, -87.53076, -87.5708...## $ lat <dbl> 30.38968, 30.37249, 30.37249, 30.33239, 30.32665, 30...## $ group <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...## $ order <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1...## $ region <chr> "alabama", "alabama", "alabama", "alabama", ...

Get Applied Data Visualization with R and ggplot2 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.