O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Labeling and legends

Labeling your graph is an important aspect of visualization, as the default variable names will not add clarity to the graph. ggplot has two ways to add labels and legends:

ggtitle(label): for adding the main titlexlab(label): for adding the x axis labelylab(label): for adding the y axis label

You can also use the labs(...) method to add all of these--the main title, axis labels, and even legend titles. In this recipe, you will learn about adding labels and legends to your plot by adding extra layers to it.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required