Box Plots

Sameer Mathur

Simple Box Plot

attach(mtcars)
boxplot(mpg,data=mtcars,
        main="Box Plot", 
        ylab="Miles Per Gallon")

Simple Box Plot

plot of chunk unnamed-chunk-2

Box Plots with Transmission Type

boxplot(mpg~am,data=mtcars,
        main="Car Milage Data", 
        xlab="Number of Cylinders", 
        ylab="Miles Per Gallon")

Box Plots with Transmission Type

plot of chunk unnamed-chunk-4

Box Plots for Transmission Type with Factors

Create a factor for transmission type

mtcars$am.f <- factor(mtcars$am, 
                      levels=c(0,1), 
                      labels=c("Automatic","Manual"))

Box Plots with Transmission Type (Automatic and Manual)

plot of chunk unnamed-chunk-6

Box Plots with Number of Cylinders

boxplot(mpg~cyl,data=mtcars,
        main="Car Milage Data", 
        xlab="Number of Cylinders", 
        ylab="Miles Per Gallon")

Box Plots with Number of Cylinders

plot of chunk unnamed-chunk-8

Box Plots for Number of Cylinders with Factors

Create a factor for number of cylinders

mtcars$cyl.f <- factor(mtcars$cyl,
                       levels=c(4,6,8),
                       labels=c("4-Cyl","6-Cyl","8-Cyl"))

Box Plots with Number of Cylinders (4 = 4-Cyl, 6 = 6-Cyl and 8 = 8-Cyl)

plot of chunk unnamed-chunk-10

Box Plots for Transmission Type and Number of Cylinders

boxplot(mpg ~ am.f *cyl.f, data=mtcars, varwidth=TRUE,col=c("gold", "darkgreen"),
        main="MPG Distribution by Auto Type",xlab="Auto Type")

Box Plots for Transmission Type and Number of Cylinders

plot of chunk unnamed-chunk-12