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

Adding flair to your graphs

By default, lattice assigns the panel's height and width based on the screen device. Also, the plots use a default color scheme. However, these can be customized to your needs.

You should change the color scheme of all the lattice plots before executing the plot command. The color scheme affects all Trellis plots made with the lattice package:

> trellis.par.set(theme = col.whitebg()) 

Panels occupy the entire output window. This can be controlled with aspect. The layout determines the number of panels on the x axis and how they are stacked. Add these to the plot function call:

> bwplot(~mpg|cyl.factor, data=auto,main="MPG by Number Of Cylinders", xlab="Miles per Gallon",layout=c(2,3),aspect=1) 

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