More power. More questions.

Does a bigger engine always mean a better drive? Explore the relationship between fuel economy, horsepower, weight and transmission in this interactive look at the classic mtcars dataset.

Scroll. Hover. Compare. Discover.

32Cars in dataset
20.1Average MPG
147Average horsepower
3.33Median weight (1000 lb)

01 — The power-efficiency trade-off

Each bubble represents a car. Move your cursor over a point to reveal its model, MPG, horsepower, weight and transmission. Use the legend to isolate transmission types.

p1 <- plot_ly(
  cars,
  x = ~hp, y = ~mpg,
  type = "scatter", mode = "markers",
  color = ~transmission,
  colors = c("#e69a45", "#238b91"),
  size = ~wt, sizes = c(10, 34),
  text = ~paste0(
    "<b>", model, "</b>",
    "<br>MPG: ", mpg,
    "<br>Horsepower: ", hp,
    "<br>Weight: ", wt, " (1000 lb)",
    "<br>Transmission: ", transmission
  ),
  hoverinfo = "text",
  marker = list(opacity = 0.82, line = list(color = "white", width = 1))
) %>%
  layout(
    xaxis = list(title = "Horsepower (hp)", gridcolor = "#e8edf2"),
    yaxis = list(title = "Miles per gallon (MPG)", gridcolor = "#e8edf2"),
    legend = list(title = list(text = "Transmission")),
    margin = list(l = 65, r = 25, b = 60, t = 20),
    paper_bgcolor = "rgba(0,0,0,0)",
    plot_bgcolor = "rgba(255,255,255,0)"
  )
p1
Look for: Is the cloud sloping down as horsepower increases? Do the heavier bubbles tend to sit lower on the MPG scale? The plot lets you inspect individual exceptions rather than relying only on an average.

02 — How do transmission types compare?

p2 <- plot_ly(
  cars, x = ~transmission, y = ~mpg,
  color = ~transmission,
  colors = c("#e69a45", "#238b91"),
  type = "box",
  boxpoints = "all",
  jitter = 0.28,
  pointpos = 0,
  text = ~model,
  hovertemplate = "%{text}<br>MPG: %{y}<extra></extra>"
) %>%
  layout(
    xaxis = list(title = "Transmission"),
    yaxis = list(title = "Miles per gallon (MPG)", gridcolor = "#e8edf2"),
    showlegend = FALSE,
    margin = list(l = 65, r = 25, b = 60, t = 20),
    paper_bgcolor = "rgba(0,0,0,0)",
    plot_bgcolor = "rgba(255,255,255,0)"
  )
p2

03 — The engine-size story

engine_summary <- cars %>%
  group_by(cylinders) %>%
  summarise(
    cars = n(),
    average_mpg = mean(mpg),
    average_hp = mean(hp),
    .groups = "drop"
  )

p3 <- plot_ly(
  engine_summary,
  x = ~cylinders, y = ~average_mpg,
  type = "bar",
  marker = list(color = c("#238b91", "#e69a45", "#4267a8")),
  text = ~paste0(
    "Cars: ", cars,
    "<br>Average MPG: ", round(average_mpg, 1),
    "<br>Average HP: ", round(average_hp, 1)
  ),
  hoverinfo = "text"
) %>%
  layout(
    xaxis = list(title = "Number of cylinders"),
    yaxis = list(title = "Average MPG", gridcolor = "#e8edf2"),
    margin = list(l = 65, r = 25, b = 60, t = 20),
    paper_bgcolor = "rgba(0,0,0,0)",
    plot_bgcolor = "rgba(255,255,255,0)"
  )
p3

04 — What can we take away?

  • In this sample, fuel economy generally tends to be lower among cars with higher horsepower.
  • Vehicle weight is another useful dimension to inspect; larger bubbles make heavier cars easy to spot.
  • The transmission comparison is descriptive, not proof that transmission alone causes a change in fuel economy.
  • Cylinder groups show how engine configuration relates to average MPG in this particular dataset.

A note on the data: mtcars is a built-in R dataset containing 32 automobiles from the 1970s. It is a small historical sample, not a modern market-wide comparison. The charts show associations and summaries, not causal conclusions.

Data is more interesting when you can play with it.

Hover over the points, compare the groups, and see which cars challenge your assumptions.

Document created on 10 November 2026 · Built with R Markdown, Plotly and the mtcars dataset.

Reproduce this presentation

The charts are generated from R code, so you can edit the dataset, colours, labels or chart types and knit the document again.

R.version.string
## [1] "R version 4.5.2 (2025-10-31 ucrt)"
packageVersion("plotly")
## [1] '4.12.1'