From the course: Data Visualization in R with ggplot2
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Adding city names
From the course: Data Visualization in R with ggplot2
Adding city names
- [Instructor] As I look at this map, it's apparent that most of these schools are located in major population centers. I know the names of the six largest cities in California, but I'm not quite sure where they're located. Let's geocode them and plot them on the map. I'm going to begin by creating a vector that includes the names of those cities We'll call it city_names and we'll put in Los Angeles, San Diego, San Jose, San Francisco, Fresno, and Sacramento. Then, I'll use the geocode function to create a vector containing the coordinates of each city. I'm going to create locations as my new object, and I'm going to fill it using geocode on city_names. That will send those off to Google to be geocoded and give me the latitude and longitude back. Now, let's put all this together in a cities tibble. I'm going to have the name in that tibble coming from the city_names vector, I'm going to have latitude coming from the latitude vector in locations. and then the same thing for longitude…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.