Activity: Creating a Variable-Encoded Regional Map

Scenario

A company wants to know which states buy their product the most. A colored map is a clear way of showing this information. Here, we use the data to create a map, differentiated with the percentage of voters that voted for Obama.

Aim

To create a map of the US that is colored according to the percentage of voters that voted for Obama. 

Steps for Completion

  1. Merge the data sets.
  2. Use the ggplot options to create the map.
  3. For aesthetics, run the required code:
USStates$Statelower <- as.character(tolower(USStates$State))glimpse(USStates)## Observations: 50## Variables: 23## $ State <fct> Alabama, Alaska, Arizona,Arkansas, Californi...## $ HouseholdIncome <dbl> 43.253, 70.760, 49.774, ...

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.