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

How to do it...

To add labels and legends, perform the following steps:

  1. Create the box plot:
> p <- ggplot(toothgrowth, aes(x=dose, y=len)) + geom_boxplot()
  1. Add a theme of your choice:
> p + theme_bw()> p + theme_dark()> p + theme_grey()# Grey back ground and white lines
  1. Change the plot background color (not the panel):
> p + theme(plot.background = element_rect(fill = "darkblue"))
  1. Modify the appearance of the axis tick mark, labels, size, and orientation:
> p + theme(axis.text.x = element_text(face="bold", color="#993333", size=14, ...

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