From the course: Data Visualization in R with ggplot2
Unlock this course with a free trial
Join today to access over 25,100 courses taught by industry experts.
Cleaning the legends
From the course: Data Visualization in R with ggplot2
Cleaning the legends
- [Instructor] Now that we have a nice map of California schools, let's make it a bit more aesthetically appealing. I already moved the plot background, panel background, and access information earlier in my code. Now I'd like to tidy up the legends. The first thing I'll do is rename the legends. The first legend is for the size of the point, and it's mapped to the undergraduate population. If you recall, we modify a legend by changing the scale for the aesthetic. In this case, the scale is for size and it's a continuous variable, so we use the scale_size_continuous function. Let's set the name of that scale to Undergraduate Population. I'm going to add on to the end here, scale_size_continuous, name equals Undergraduate Population. And that changes the name of one legend. Then let's modify the one for color as well. This is a discrete variable mapped to institutional control, so we use the scale_color_discrete function to change its name to Institutional Control. And there we go, our…
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.