Main takeaway
- Smaller engines tend to deliver better fuel economy.
- Manual cars often appear among the more efficient models.
- High-horsepower cars are concentrated in the low-MPG region.
Isi
abril 27, 2026
mtcars dataset is used to create the interactive
Plotly chart.This presentation uses 32 car models from the built-in
mtcars dataset.
mpg: miles per gallondisp: engine displacementhp: horsepowerwt: vehicle weightam: transmission typecyl: number of cylindersThis 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"
)
)