Due Date: 11:59pm, Oct 25
library(tidyverse)
library(tidyr) # load tidyr package
library(plotly) # load plotly package
data(EuStockMarkets) # load EuStockMarkets
dat <- as.data.frame(EuStockMarkets) # coerce it to a data frame
dat$time <- time(EuStockMarkets) # add `time` variable
longdat <- gather(dat, key = 'stock', value = 'price', -time)
longdat$stock <- as.factor(longdat$stock)
fig <- plot_ly(longdat, x = ~time, y = ~price, type = 'scatter',
color = longdat$stock, mode = 'lines')
fig
This dataset has different measurements of penguins. It was collected and made publicly available by Dr. Kristen Gorman and the Palmer Station, Antarctica LTER, a member of the Long Term Ecological Research Network. The dataset is made up of 8 columns: species, island, bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g, sex, and year. The dataset can be found on kaggle with this link: https://www.kaggle.com/larsen0966/penguins. The columns are explained more in depth below.
penguins <- read_csv("~/Desktop/DS3003/penguins.csv")
longpenguins <- gather(penguins, key = penguin_att, value = measurement,
'bill_length_mm':'bill_depth_mm')
longpenguins$species <- as.factor(longpenguins$species)
fig <- ggplot(longpenguins, aes(x=species, y=measurement, fill=species)) +
geom_boxplot() + facet_grid(~ penguin_att) + theme_classic() +
labs(title='Boxplots for Bill Depth and Bill Length', fill='Species') +
xlab('Species') + ylab('Measurement (mm)') +
theme(plot.title = element_text(hjust = 0.5))
ggplotly(fig)
The boxplot compares the bill depths and bill lengths of each species of penguin. While the Adelie and Chinstrap penguins appear to be close in size in terms of bill depth, the Chinstrap penguin’s bill is slightly larger with a median bill depth of 18.45 mm compared to 18.40 mm for the Adelie penguin. The Gentoo penguin’s bill depth is smaller with a median bill depth of 15.00 mm. As for bill length, the Chinstrap penguin has a longer bill with a median bill length of 49.55 mm. The Gentoo penguin has a slightly shorter bill with a median bill length of 47.30 mm. The Adelie penguin has the shortest bill with a median bill length of 38.80 mm. The Adelie penguin has an outlier for bill depth and the Gentoo penguin has an outlier for bill length.