Sometimes, we want to know the trends and behaviors of people in different countries or states. For example, we might want to see the shopping behaviors of people in different states. The maps
package is useful for this purpose. In this section, we will look at how to draw and display 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:
- Install the
maps
package usingmap_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,...