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
y axes as well as a
caption. You can check out the list of available label arguments in the
labs() documentation here.
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
The labels on the plot we’ve been building could definitely use an update!
labs() function call and change the following arguments:
"Movie Ratings Vs Award Wins"to contextualize the goal of the plot
"From IMDB dataset"
"Movie Rating"and the
"Number of Award Wins"
colorargument with the string value of
"Number of Genre"