Executive Summary

Welcome to our interactive exploration of automotive performance data! This presentation analyzes the famous mtcars dataset using modern data visualization techniques with Plotly interactive charts.

Our analysis reveals fascinating insights about the relationships between fuel efficiency, engine power, and vehicle characteristics across different car models from the 1970s.


Dataset Overview

The mtcars dataset contains performance specifications for 32 automobile models from 1973-1974 Motor Trend magazine. Let’s examine the structure of our data:

# Load and prepare the data
data(mtcars)
mtcars_enhanced <- mtcars %>%
  mutate(
    car_name = rownames(mtcars),
    transmission = ifelse(am == 0, "Automatic", "Manual"),
    engine_type = ifelse(vs == 0, "V-shaped", "Straight"),
    cylinders = as.factor(cyl)
  ) %>%
  select(car_name, everything())

# Display summary statistics
summary_stats <- mtcars_enhanced %>%
  select(mpg, hp, wt, qsec, disp) %>%
  summary()

kable(summary_stats, caption = "Summary Statistics of Key Variables") %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
Summary Statistics of Key Variables
mpg hp wt qsec disp
Min. :10.40 Min. : 52.0 Min. :1.513 Min. :14.50 Min. : 71.1
1st Qu.:15.43 1st Qu.: 96.5 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:120.8
Median :19.20 Median :123.0 Median :3.325 Median :17.71 Median :196.3
Mean :20.09 Mean :146.7 Mean :3.217 Mean :17.85 Mean :230.7
3rd Qu.:22.80 3rd Qu.:180.0 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:326.0
Max. :33.90 Max. :335.0 Max. :5.424 Max. :22.90 Max. :472.0

Key Variables Description

  • mpg: Miles per gallon (fuel efficiency)
  • hp: Horsepower (engine power)
  • wt: Weight in thousands of pounds
  • qsec: Quarter mile time in seconds
  • disp: Engine displacement in cubic inches
  • cyl: Number of cylinders
  • am: Transmission type (0 = automatic, 1 = manual)
  • vs: Engine shape (0 = V-shaped, 1 = straight)
# Interactive data table
datatable(mtcars_enhanced, 
          caption = "Complete mtcars Dataset with Enhanced Variables",
          options = list(pageLength = 10, scrollX = TRUE),
          class = 'cell-border stripe') %>%
  formatRound(columns = c('mpg', 'wt', 'qsec'), digits = 2)

Interactive Visualizations

Fuel Efficiency vs Engine Power

# Create interactive scatter plot
p1 <- mtcars_enhanced %>%
  plot_ly(x = ~hp, y = ~mpg, 
          color = ~transmission,
          colors = c("Automatic" = "#e74c3c", "Manual" = "#3498db"),
          text = ~paste("Car:", car_name, 
                       "<br>HP:", hp,
                       "<br>MPG:", mpg,
                       "<br>Weight:", wt, "k lbs"),
          hovertemplate = "%{text}<extra></extra>") %>%
  add_markers(size = ~wt, sizes = c(50, 200), alpha = 0.7) %>%
  layout(title = list(text = "Fuel Efficiency vs Engine Power", 
                     font = list(size = 16)),
         xaxis = list(title = "Horsepower"),
         yaxis = list(title = "Miles per Gallon (MPG)"),
         legend = list(title = list(text = "Transmission")))

p1

Weight vs Fuel Efficiency Analysis

# Weight vs MPG colored by cylinders
p2 <- mtcars_enhanced %>%
  plot_ly(x = ~wt, y = ~mpg, 
          color = ~cylinders,
          colors = "viridis",
          text = ~paste("Car:", car_name,
                       "<br>Weight:", wt, "k lbs",
                       "<br>MPG:", mpg,
                       "<br>Cylinders:", cyl),
          hovertemplate = "%{text}<extra></extra>") %>%
  add_markers(size = I(10), alpha = 0.8) %>%
  layout(title = list(text = "Vehicle Weight vs Fuel Efficiency", 
                     font = list(size = 16)),
         xaxis = list(title = "Weight (1000 lbs)"),
         yaxis = list(title = "Miles per Gallon (MPG)"),
         legend = list(title = list(text = "Cylinders")))

p2

Performance Distribution by Engine Configuration

# Box plot of horsepower by cylinders
p3 <- mtcars_enhanced %>%
  plot_ly(y = ~hp, color = ~cylinders, type = "box",
          colors = c("4" = "#2ecc71", "6" = "#f39c12", "8" = "#e74c3c")) %>%
  layout(title = list(text = "Horsepower Distribution by Cylinder Count", 
                     font = list(size = 16)),
         xaxis = list(title = "Number of Cylinders"),
         yaxis = list(title = "Horsepower"),
         legend = list(title = list(text = "Cylinders")))

p3

Transmission Type Performance Comparison

# Summary statistics by transmission
transmission_stats <- mtcars_enhanced %>%
  group_by(transmission) %>%
  summarise(
    avg_mpg = mean(mpg),
    avg_hp = mean(hp),
    avg_wt = mean(wt),
    count = n(),
    .groups = 'drop'
  )

# Create grouped bar chart
p4 <- transmission_stats %>%
  plot_ly(x = ~transmission, y = ~avg_mpg, 
          type = 'bar', name = 'Avg MPG',
          marker = list(color = '#3498db'),
          text = ~paste("MPG:", round(avg_mpg, 1)),
          textposition = 'outside') %>%
  add_trace(y = ~avg_hp/10, name = 'Avg HP (÷10)', 
           marker = list(color = '#e74c3c'),
           text = ~paste("HP:", round(avg_hp, 0)),
           textposition = 'outside') %>%
  layout(title = list(text = "Average Performance by Transmission Type", 
                     font = list(size = 16)),
         xaxis = list(title = "Transmission Type"),
         yaxis = list(title = "Value"),
         barmode = 'group',
         legend = list(x = 0.7, y = 0.95))

p4

Statistical Analysis

Correlation Analysis

# Calculate correlation matrix
numeric_vars <- mtcars_enhanced %>%
  select(mpg, hp, wt, qsec, disp, cyl, am, vs) %>%
  cor()

# Display correlation table
kable(round(numeric_vars, 3), 
      caption = "Correlation Matrix of Key Variables") %>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"))
Correlation Matrix of Key Variables
mpg hp wt qsec disp cyl am vs
mpg 1.000 -0.776 -0.868 0.419 -0.848 -0.852 0.600 0.664
hp -0.776 1.000 0.659 -0.708 0.791 0.832 -0.243 -0.723
wt -0.868 0.659 1.000 -0.175 0.888 0.782 -0.692 -0.555
qsec 0.419 -0.708 -0.175 1.000 -0.434 -0.591 -0.230 0.745
disp -0.848 0.791 0.888 -0.434 1.000 0.902 -0.591 -0.710
cyl -0.852 0.832 0.782 -0.591 0.902 1.000 -0.523 -0.811
am 0.600 -0.243 -0.692 -0.230 -0.591 -0.523 1.000 0.168
vs 0.664 -0.723 -0.555 0.745 -0.710 -0.811 0.168 1.000

Key Insights

# Generate summary insights
insights <- mtcars_enhanced %>%
  summarise(
    total_cars = n(),
    avg_mpg = round(mean(mpg), 1),
    max_mpg = max(mpg),
    min_mpg = min(mpg),
    avg_hp = round(mean(hp), 0),
    max_hp = max(hp),
    manual_count = sum(am == 1),
    auto_count = sum(am == 0),
    manual_avg_mpg = round(mean(mpg[am == 1]), 1),
    auto_avg_mpg = round(mean(mpg[am == 0]), 1)
  )

insight_table <- data.frame(
  Metric = c("Total Cars Analyzed", "Average MPG", "MPG Range", 
             "Average Horsepower", "Max Horsepower",
             "Manual Transmission Cars", "Manual Avg MPG",
             "Automatic Transmission Cars", "Automatic Avg MPG"),
  Value = c(insights$total_cars, 
           paste(insights$avg_mpg, "mpg"),
           paste(insights$min_mpg, "-", insights$max_mpg, "mpg"),
           paste(insights$avg_hp, "hp"),
           paste(insights$max_hp, "hp"),
           insights$manual_count,
           paste(insights$manual_avg_mpg, "mpg"),
           insights$auto_count,
           paste(insights$auto_avg_mpg, "mpg"))
)

kable(insight_table, caption = "Dataset Summary Insights") %>%
  kable_styling(bootstrap_options = c("striped", "hover"))
Dataset Summary Insights
Metric Value
Total Cars Analyzed 32
Average MPG 20.1 mpg
MPG Range 10.4 - 33.9 mpg
Average Horsepower 147 hp
Max Horsepower 335 hp
Manual Transmission Cars 13
Manual Avg MPG 24.4 mpg
Automatic Transmission Cars 19
Automatic Avg MPG 17.1 mpg

Conclusions

Key Findings

  1. Fuel Efficiency Trade-off: There’s a strong negative correlation (-0.776) between horsepower and fuel efficiency
  2. Weight Impact: Vehicle weight shows the strongest negative correlation with MPG (-0.868)
  3. Transmission Advantage: Manual transmissions achieve better fuel economy on average
  4. Engine Configuration: 4-cylinder engines provide the best fuel efficiency, while 8-cylinder engines offer maximum power

Performance Champions

# Identify top performers
top_efficient <- mtcars_enhanced[which.max(mtcars_enhanced$mpg), ]
top_powerful <- mtcars_enhanced[which.max(mtcars_enhanced$hp), ]
lightest <- mtcars_enhanced[which.min(mtcars_enhanced$wt), ]

champions <- data.frame(
  Category = c("Most Fuel Efficient", "Most Powerful", "Lightest Vehicle"),
  Car = c(top_efficient$car_name, top_powerful$car_name, lightest$car_name),
  Value = c(paste(top_efficient$mpg, "MPG"), 
           paste(top_powerful$hp, "HP"),
           paste(lightest$wt, "k lbs"))
)

kable(champions, caption = "Performance Champions") %>%
  kable_styling(bootstrap_options = c("striped", "hover"))
Performance Champions
Category Car Value
Most Fuel Efficient Toyota Corolla 33.9 MPG
Most Powerful Maserati Bora 335 HP
Lightest Vehicle Lotus Europa 1.513 k lbs

This analysis demonstrates the complex relationships between automotive performance characteristics and provides valuable insights for understanding vehicle design trade-offs from the 1970s era.


Analysis completed using R with Plotly for interactive visualizations