How to do it...

Perform the following steps:

  1. First we plot the two boxplots of factor gears regarding mpg, with the plot separated from the transmission type:
        > par(mfrow=c(1,2))        > boxplot          (mtcars$mpg~mtcars$gear,subset=(mtcars$am==0),xlab='gear'         , ylab = "mpg",main='automatic')         > boxplot         (mtcars$mpg~mtcars$gear,subset=(mtcars$am==1),xlab='gear',         ylab = "mpg", main='manual')
The boxplots of mpg by the gear group and the transmission type
  1. Also, you may produce a boxplot of mpg by the number of forward gears * transmission type, with the use of the * operation in the boxplot function:
        > boxplot(mtcars$mpg~factor(mtcars$gear)* factor(mtcars$am),xlab='gear ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.