November 18, 2016

Objective

My objective is to show the relationship between car weight, mileage, number of cylinders, and horsepower I do this in two ways.

First, I print summary statistics for each of these variables to show how they are distributed.

Second, I use the plotly package to plot all four of these variables simultaneously. I do this by first plotting weight on the x-axis and mileage on the y-axis. I then make the point size dependent on the car's horsepower and point color dependent on the number of cylinders.

Summary

##       mpg             cyl              hp              wt       
##  Min.   :10.40   Min.   :4.000   Min.   : 52.0   Min.   :1.513  
##  1st Qu.:15.43   1st Qu.:4.000   1st Qu.: 96.5   1st Qu.:2.581  
##  Median :19.20   Median :6.000   Median :123.0   Median :3.325  
##  Mean   :20.09   Mean   :6.188   Mean   :146.7   Mean   :3.217  
##  3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:180.0   3rd Qu.:3.610  
##  Max.   :33.90   Max.   :8.000   Max.   :335.0   Max.   :5.424

Graphical examination

Summary

Cars with fewer cylinders tend to have greater mileage. In addition, there is a negative relationship between weight and mileage.