So far, we’ve reviewed how to add geometries to represent our data. We’ve also learned how to modify aesthetic values in our plot- whether those aesthetics are data-driven or assigned manually. Another big part of creating a plot is in making sure it has reader-friendly labels. The ggplot2 package automatically assigns the name of the variable corresponding to the different components on the plot as the initial label. Code variable names are unfortunately not always legible to outside readers with no context.
If you wish to customize your labels, you can add a labs()
function call to your ggplot object. Inside the function call to labs()
you can provide new labels for the x
and y
axes as well as a title
, subtitle
, or caption
. You can check out the list of available label arguments in the labs()
documentation here.
The following labs()
function call and these specified arguments would render the following plot:
viz <- ggplot(df, aes(x=rent, y=size_sqft)) + geom_point() + labs(title="Monthly Rent vs Apartment Size in Brooklyn, NY", subtitle="Data by StreetEasy (2017)", x="Monthly Rent ($)", y="Apartment Size (sq ft.)") viz
Instructions
The labels on the plot we’ve been building could definitely use an update!
Add a labs()
function call and change the following arguments:
- Change the
title
to"Movie Ratings Vs Award Wins"
to contextualize the goal of the plot - Contextualize details about where the data comes from inside the
subtitle
by adding"From IMDB dataset"
- Change the
x
label to"Movie Rating"
and they
label to"Number of Award Wins"
- Change the legend label by providing a
color
argument with the string value of"Number of Genre"