Introduction

This webpage presents an interactive visualization created using Plotly in R Markdown.

The goal is to explore the relationship between vehicle weight, fuel efficiency, and transmission type using the built-in mtcars dataset.

The interactive graph allows users to hover over points and explore individual cars.

data(mtcars)

mtcars <- mtcars %>%
  mutate(
    car = rownames(mtcars),
    transmission = ifelse(am == 1, "Manual", "Automatic")
  )


fig <- plot_ly(
  mtcars,
  x = ~wt,
  y = ~mpg,
  type = "scatter",
  mode = "markers",
  color = ~transmission,
  size = ~hp,
  text = ~paste(
    "Car:", car,
    "<br>Weight:", wt,
    "<br>MPG:", mpg,
    "<br>Horsepower:", hp,
    "<br>Transmission:", transmission
  ),
  hoverinfo = "text"
)


fig <- fig %>%
  layout(
    title = "Interactive Exploration of Fuel Efficiency",
    xaxis = list(title = "Vehicle Weight (1000 lbs)"),
    yaxis = list(title = "Miles per Gallon (MPG)")
  )


fig

Introduction

This interactive webpage explores the Palmer Penguins dataset using Plotly.

The visualization examines how penguin species differ in body size and physical characteristics. Users can hover over individual penguins to explore their measurements.

library(palmerpenguins)

penguins_clean <- penguins %>%
  filter(!is.na(body_mass_g),
         !is.na(flipper_length_mm),
         !is.na(species))


fig <- plot_ly(
  penguins_clean,
  x = ~flipper_length_mm,
  y = ~body_mass_g,
  type = "scatter",
  mode = "markers",
  color = ~species,
  size = ~bill_length_mm,
  text = ~paste(
    "Species:", species,
    "<br>Island:", island,
    "<br>Sex:", sex,
    "<br>Flipper length:", flipper_length_mm, "mm",
    "<br>Body mass:", body_mass_g, "g"
  ),
  hoverinfo = "text"
)


fig <- fig %>%
  layout(
    title = "Relationship Between Flipper Length and Body Mass in Penguins",
    xaxis = list(
      title = "Flipper Length (mm)"
    ),
    yaxis = list(
      title = "Body Mass (g)"
    )
  )


fig