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

Histograms

By default, the hist() function automatically determines the number of bars to display, based on the data. The breaks argument controls this.

You can also use a palette of colors instead of a single color, by using the following command:

> hist(mpg, col = rainbow(12)) 

The following diagram is the colored histogram:

The rainbow() function returns a color palette with the color spectrum broken into the number of distinct colors specified, and the hist() function uses one color for each bar.

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