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

Using base plotting system

Now we'll look at how to generate histograms of the count of daily bike rentals by season, using R's base plotting system:

  1. Set up a 2 x 2 grid for plotting histograms for the four seasons:
> par(mfrow = c(2,2)) 
  1. Extract data for seasons:
> spring <- subset(bike, season == "Spring")$cnt > summer <- subset(bike, season == "Summer")$cnt > fall <- subset(bike, season == "Fall")$cnt > winter <- subset(bike, season == "Winter")$cnt 
  1. Plot the histogram, density, mean, and median for each season:
> hist(spring, prob=TRUE, xlab = "Spring daily rentals", main = "")> lines(density(spring))> abline(v = mean(spring), col = "red")> abline(v = median(spring), col = "blue")> hist(summer, prob=TRUE, xlab = "Summer daily rentals", ...

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