mtcars+Plotly

Ermeson

2026-04-21

Introduction

This presentation shows an interactive Plotly chart created with the mtcars dataset.

The goal is to explore the relationship between car weight and fuel efficiency.

The Dataset

The mtcars dataset contains information about different car models, including:

Interactive Plot

library(plotly)

plot_ly(
  data = mtcars,
  x = ~wt,
  y = ~mpg,
  type = "scatter",
  mode = "markers",
  color = ~factor(cyl),
  text = ~paste(
    "Car:", rownames(mtcars),
    "<br>Weight:", wt,
    "<br>MPG:", mpg,
    "<br>Cylinders:", cyl
  ),
  hoverinfo = "text"
) %>%
  layout(
    title = "Fuel Efficiency vs Car Weight",
    xaxis = list(title = "Weight (1000 lbs)"),
    yaxis = list(title = "Miles per Gallon (MPG)")
  )