2025-11-03

The Dataset

The mtcars dataset (Motor Trend, 1974) includes 32 car models and 11 variables related to performance and design.
Key features include miles per gallon (mpg), weight (wt), horsepower (hp), and transmission type (am).

This dataset is widely used in data analysis to explore how car design choices influence fuel efficiency and overall performance.

Brief Overview

  • This presentation explores how car features affect fuel efficiency using the mtcars dataset.
  • A scatterplot visualizes the relationship between MPG, weight, horsepower, and cylinder count.
  • A boxplot compares fuel efficiency across cars with different cylinder numbers.
  • A 3D scatterplot adds an interactive view of how weight and horsepower relate to MPG.
  • Descriptive statistics summarize key values like the mean and median for each variable.
  • A regression model predicts MPG based on weight, horsepower, and cylinders.
  • Diagnostic plots test how well the model fits the data and assess accuracy.

This scatterplot shows how a car’s weight and horsepower relate to its fuel efficiency We can see that heavier, more powerful cars generally have lower MPG, while smaller cars are more fuel-efficient.

Ggplot Boxplot Code

To compare fuel efficiency across cars with different cylinder counts, a boxplot was created using ggplot2.
This visualization helps highlight how cars with more cylinders generally have lower miles per gallon (MPG).
Below is the R code used to create this boxplot:

ggplot(mtcars_df, aes(x = factor(cyl), y = mpg, fill = factor(cyl))) +
  geom_boxplot(alpha = 0.8, outlier.shape = 21) +
  labs(title = "MPG Distribution by Cylinder Count",
       x = "Cylinders",
       y = "Miles per Gallon (MPG)") +
  theme_minimal(base_size = 14)

This boxplot compares fuel efficiency across cars with 4, 6, and 8 cylinders. It shows that 4-cylinder cars have the highest MPG, while 8-cylinder cars tend to use more fuel.

This interactive 3D plot visualizes the relationship between weight, horsepower, and MPG all at once.
It highlights how lighter cars with less horsepower achieve better fuel economy.

This boxplot compares automatic vs. manual transmissions in terms of fuel efficiency.
Overall, manual cars tend to have slightly higher MPG, suggesting better fuel economy.

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

The descriptive statistics of the dataset provide insight into overall vehicle performance trends. On average, cars achieve approximately 20 miles per gallon, weigh about 3,200 pounds, and produce around 146 horsepower. The median MPG is slightly lower than the mean, suggesting that a few high-efficiency cars pull the average upward. The five-number summary (minimum, first quartile, median, third quartile, and maximum) shows moderate variation in weight and horsepower, but a wider spread in MPG.

## Diagnostic Plots
These diagnostic plots help assess how well the regression model fits the data. The Residuals vs Fitted plot checks for randomness which shows that most residuals are evenly scattered, meaning the model captures the main trend. The Q–Q plot tests the normality of residuals, and since most points lie close to the diagonal line, the assumption of normality holds fairly well. Overall, the diagnostics suggest the regression model provides a reasonably good fit with no major violations.

Conclusion

Through this analysis, we explored how different car characteristics impact fuel efficiency using the mtcars dataset.
The results showed that weight and horsepower have a strong negative effect on miles per gallon as heavier and more powerful cars tend to consume more fuel.
Vehicles with fewer cylinders generally achieved higher MPG, highlighting the efficiency advantage of smaller engines.
Diagnostic checks confirmed that the regression model fits the data reasonably well, with residuals displaying no major patterns or violations.
Overall, this study demonstrates how quantitative data can effectively capture relationships between design choices and performance.
These insights could guide manufacturers or consumers in balancing power, weight, and efficiency when evaluating car models.