From the course: Creating Maps with R

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

ggplot2 choropleth and discrete data

ggplot2 choropleth and discrete data

From the course: Creating Maps with R

ggplot2 choropleth and discrete data

- [Instructor] We're going to use ggplot2 to create a choropleth of a discrete variable, specifically the most popular pets that aren't cats or dogs in each of the states in a contiguous United States. To start this map, I'd like you to open the script in the 04_03b project. And let's go through the code. We're going to load our packages on lines 1 through 5, line 7 through 8, we'll read in our dataset, lines 10 through 15, we're going to filter for the contiguous United States of America, and finally on line 17 through 19, we're going to join our two datasets together into one SF object. I'm also providing custom colors for each of the pets, which I define on lines 21 through 28. Let's give ourselves some space with some new lines. And I'll scroll down. And let's start our map off with the function ggplot. And we'll add a geom_sf layer, with the argument data is equal to US most popular pets. And that's the start of…

Contents