I chose to work with the ‘palmerpenguins’ dataset. Per the internet, this dataset is a small step up in difficulty from the ‘iris’ dataset. The main reason is the imperfect data when compared to the ‘iris’ dataset. ‘palmerpenguins’ was compiled and collected about a set of penguins in Antartica between 2007 and 2009.
# Libraries
library(palmerpenguins)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.0 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
A quick look at the data…
head(penguins)
## # A tibble: 6 × 8
## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
## <fct> <fct> <dbl> <dbl> <int> <int>
## 1 Adelie Torgersen 39.1 18.7 181 3750
## 2 Adelie Torgersen 39.5 17.4 186 3800
## 3 Adelie Torgersen 40.3 18 195 3250
## 4 Adelie Torgersen NA NA NA NA
## 5 Adelie Torgersen 36.7 19.3 193 3450
## 6 Adelie Torgersen 39.3 20.6 190 3650
## # ℹ 2 more variables: sex <fct>, year <int>
A quick calculation…
# Calculating mean body mass by species
penguins %>%
group_by(species) %>%
summarize(mean_mass_g = mean(body_mass_g, na.rm = TRUE))
## # A tibble: 3 × 2
## species mean_mass_g
## <fct> <dbl>
## 1 Adelie 3701.
## 2 Chinstrap 3733.
## 3 Gentoo 5076.
Using Plotly instead of Shiny…
p <- ggplot(data = penguins,
aes(x = flipper_length_mm,
y = body_mass_g,
color = species)) +
geom_point(alpha = 0.7) +
labs(x = "Flipper Length (mm)",
y = "Body Mass (g)",
title = "Penguin Size: Flipper Length vs Body Mass") +
theme_minimal()
ggplotly(p)