From the course: Data Visualization in R with ggplot2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Cleaning the legends

Cleaning the legends

From the course: Data Visualization in R with ggplot2

Start my 1-month free trial

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 removed the plot background, panel background, and axis information earlier in my code, and now I'd like to tidy up the legends. The first thing that I'd like to 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 associated with the legend. In this case, the scale is for size, and it's a continuous variable, so we use the scale_size_continuous function. We'll go ahead and set the name of that scale to undergraduate population. So I'm going to add a plus operator after my last ggplot call to geom_text, and I'm going to add a call to scale_size_continuous and I'm going to set the name of that scale to undergraduate population. I'd also like to modify the name of the legend used for color. This is a discreet variable…

Contents