Load Libraries

library(tidyverse)
library(ggplot2)
library(palmerpenguins)
library(plotly)
library(viridis)
library(reshape2)

data(penguins)

penguins <- penguins %>%
  drop_na()

Figure 1: Bill Length vs Flipper Length

ggplot(penguins,
       aes(x = bill_length_mm,
           y = flipper_length_mm,
           color = species)) +
  geom_point(size = 3) +
  labs(
    title = "Bill Length vs Flipper Length",
    x = "Bill Length (mm)",
    y = "Flipper Length (mm)"
  ) +
  theme_minimal()

This scatter plot shows the relationship between bill length and flipper length across penguin species.

Figure 2: Body Mass Distribution

ggplot(penguins,
       aes(x = species,
           y = body_mass_g,
           fill = species)) +
  geom_boxplot() +
  labs(
    title = "Body Mass Distribution by Species",
    x = "Species",
    y = "Body Mass (g)"
  ) +
  theme_minimal()

Gentoo penguins generally have the greatest body mass.

Figure 3: Distribution of Bill Length

ggplot(penguins,
       aes(x = bill_length_mm,
           fill = species)) +
  geom_histogram(alpha = 0.7, bins = 25) +
  labs(
    title = "Distribution of Bill Length",
    x = "Bill Length (mm)",
    y = "Count"
  ) +
  theme_minimal()

This histogram illustrates the distribution of bill lengths.

Figure 4: Penguins by Island

ggplot(penguins,
       aes(x = island,
           fill = species)) +
  geom_bar() +
  labs(
    title = "Penguins by Island",
    x = "Island",
    y = "Count"
  ) +
  theme_minimal()

This bar chart compares the number of penguins observed on each island.

Figure 5: Flipper Length Distribution

ggplot(penguins,
       aes(x = species,
           y = flipper_length_mm,
           fill = species)) +
  geom_violin() +
  labs(
    title = "Flipper Length Distribution",
    x = "Species",
    y = "Flipper Length (mm)"
  ) +
  theme_minimal()

Violin plots display both the distribution and density of flipper lengths.

Figure 6: Correlation Heatmap

cor_data <- penguins %>%
  select(where(is.numeric))

cor_matrix <- cor(cor_data)

melted <- melt(cor_matrix)

ggplot(melted,
       aes(x = Var1,
           y = Var2,
           fill = value)) +
  geom_tile() +
  scale_fill_viridis_c() +
  labs(
    title = "Correlation Heatmap",
    x = "",
    y = ""
  ) +
  theme_minimal()

This heatmap displays correlations among numeric variables.

Figure 7: Average Body Mass by Year

penguins %>%
  group_by(year, species) %>%
  summarise(avg = mean(body_mass_g), .groups = "drop") %>%
  ggplot(aes(x = year,
             y = avg,
             color = species)) +
  geom_line(linewidth = 1.2) +
  geom_point(size = 3) +
  labs(
    title = "Average Body Mass by Year",
    x = "Year",
    y = "Average Body Mass (g)"
  ) +
  theme_minimal()

This line chart compares average body mass across years.

Figure 8: Interactive Scatter Plot

p <- ggplot(
  penguins,
  aes(
    x = bill_length_mm,
    y = bill_depth_mm,
    color = species,
    text = paste(
      "Species:", species,
      "<br>Island:", island,
      "<br>Body Mass:", body_mass_g, "g"
    )
  )
) +
  geom_point(size = 3) +
  labs(
    title = "Interactive Scatter Plot",
    x = "Bill Length (mm)",
    y = "Bill Depth (mm)"
  ) +
  theme_minimal()

ggplotly(p, tooltip = "text")

This interactive figure allows users to hover over each point to view additional information.