Fuel Efficiency and Engine Size in Classic Cars

Isi
abril 27, 2026

Why this topic?

What the data includes

This presentation uses 32 car models from the built-in mtcars dataset.

Interactive plot

This slide contains the Plotly code followed by the interactive chart. Hover over each point to inspect a car model, drag to zoom, or use the Plotly toolbar.

plot_ly(
  data = cars,
  x = ~disp,
  y = ~mpg,
  color = ~transmission,
  colors = c("#1b6ca8", "#d95f02"),
  size = ~hp,
  sizes = c(12, 36),
  text = ~paste(
    "<b>", model, "</b><br>",
    "Horsepower: ", hp, "<br>",
    "Weight: ", wt, " (1000 lbs)<br>",
    "Cylinders: ", cylinders
  ),
  hoverinfo = "text",
  type = "scatter",
  mode = "markers",
  width = 900,
  height = 430
) %>%
  layout(
    title = "Fuel efficiency falls as engine displacement grows",
    xaxis = list(title = "Displacement"),
    yaxis = list(title = "Miles per gallon"),
    legend = list(title = list(text = "Transmission"))
  ) %>%
  config(
    displayModeBar = TRUE,
    displaylogo = TRUE,
    modeBarButtonsToRemove = c(
      "toImage",
      "zoom2d",
      "pan2d",
      "select2d",
      "lasso2d",
      "zoomIn2d",
      "zoomOut2d",
      "autoScale2d",
      "resetScale2d",
      "hoverClosestCartesian",
      "toggleSpikelines"
    )
  )

Main takeaway