2025-11-03
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.
| 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. |
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 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 |
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.