The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles. My objective is to identify the trend on number of miles a car can travel per gallon of fuel consumption based on the horsepower. A third variable Engine has also been added in the visualization which comprises of only two values 0 and 1 where 0 means V-shaped engine and 1 means straight engine
Visualization displayed below has been created using ggplot() function with arguments as Horsepower for data on X-Axis and Miles per gallon on Y-axis. The plot shows a decreasing trendline through which it can be inferred that the number of miles per gallon decreases with an increase in horspower for the automobiles. Also, we can observe that the type of engine is mostly V-shaped for automobiles having higher horsepower and those with lower horsepower have straight engines.
library(tidyverse)
ggplot(data = mtcars, aes(x = hp, y = mpg,stroke = 1)) +
geom_point(alpha = .25, aes(color = factor(vs))) +
scale_y_continuous(name = "Miles/gallon") +
scale_x_log10(name = " Gross horsepower ", labels = scales::comma) +
ggtitle("US Automobiles Mileage Trend",
subtitle = "Fuel consumption data for 1973-74 automobile models provided by the Motor Trend US magazine") +
geom_smooth()