We have used the ‘Auto-MPG Data’ datasetto understand how weight (wt), horsepower (hp), and number of cylinders (cyl) affects the acceleration of a car. And also to visualise the horspower and displacement variations in the dataset. The dataset contains the technical specifications of the various vehicles. The dataset is downloaded from the UCI Machine Learning Repository.
Plotting the acceleration along the x axis and the horsepower along the y axis we obtain the plot shown below. Number of cylinders in the engine is visualized by the use of different colors and the weight of the cars are visualized by the size of an individuals point of the plot.
suppressPackageStartupMessages(library(plotly))
plot_ly(data = cars, x = ~acceleration, y = ~horsepower,
color = ~as.factor(cylinders), size = ~weight,
text = ~paste("0 - 60mph : ", acceleration, 'sec <br>Horsepower: ', horsepower,'<br>Displacement : ', displacement ,'ci <br>Weight : ',weight,'lbs <br>Model:',car.name, '<br> Year : 19',model.year),
type = "scatter", mode = 'markers') %>%
layout(title = "Acceleration vs Horsepower")
Plotting the horsepower along the x axis and the displacement along the y axis we obtain the plot shown below. Number of cylinders in the engine is visualized by the use of different colors.
plot_ly(data = cars, x = ~horsepower, y = ~displacement,
color = ~as.factor(cylinders),
text = ~paste("Horsepower : ", horsepower, 'hp <br>Displacement : ', displacement ,'ci <br>Model : ',car.name, '<br>Year : 19', model.year),
type = "scatter", mode = 'markers') %>%
layout(title = "Horsepower vs Displacement")
Dataset: UCI Machine Learning Repository
Data link : https://archive.ics.uci.edu/ml/datasets/auto+mpg