Figure 1: Ternary plot that shows the distribution of the palmer penguins species by bill length, body mass, and flipper length. This illustrates that flipper length is a distinguishing feature, as shown along the horizontal axis, where Adelie’s tend to have smaller flippers, while Gentoo’s tend to have larger flippers.
Figure 2: Ridge plot illustrating the distribution of body mass (in g) by the three islands in the dataset: Torgersen, Dream, and Briscoe. Briscoe island is home to larger penguins than the other islands in the dataset.
1. Load Packages & Setup
Show code
if(!require("pacman"))install.packages("pacman")pacman::p_load(tidyverse,tidytuesdayR,dlookr,ggtext,gt,gtExtras, #for font awesome icons in gt tablesggbump,showtext,janitor, #for clean_names()scales,htmltools, #for tagList()glue,here,ggridges,ggtern,geomtextpath)font_add_google("Lato")
species island bill_length_mm bill_depth_mm
Length:344 Length:344 Min. :32.10 Min. :13.10
Class :character Class :character 1st Qu.:39.23 1st Qu.:15.60
Mode :character Mode :character Median :44.45 Median :17.30
Mean :43.92 Mean :17.15
3rd Qu.:48.50 3rd Qu.:18.70
Max. :59.60 Max. :21.50
NA's :2 NA's :2
flipper_length_mm body_mass_g sex year
Min. :172.0 Min. :2700 Length:344 Min. :2007
1st Qu.:190.0 1st Qu.:3550 Class :character 1st Qu.:2007
Median :197.0 Median :4050 Mode :character Median :2008
Mean :200.9 Mean :4202 Mean :2008
3rd Qu.:213.0 3rd Qu.:4750 3rd Qu.:2009
Max. :231.0 Max. :6300 Max. :2009
NA's :2 NA's :2
pen_mass_by_island_ridgeplot_viz<-penguins_complete%>%ggplot(.)+ggridges::geom_density_ridges2(aes(x=body_mass_g, y=island, fill=island), color='black', bandwidth=195)+labs(x='\nBody mass (g)', y='', title ='Distribution of the body mass of penguins on the Palmer Archipeligo', subtitle =glue("on <span style='color:maroon1'>**Torgersen**</span>, <span style='color:seagreen3'>**Dream**</span>, and <span style='color:cornflowerblue'>**Briscoe**</span> islands"), caption ='Tidy Tuesday Week 31 (2020)<br>**Source**: palmerpenguins::')+scale_x_continuous(labels =comma)+scale_fill_manual(values =peng_cols)+my_theme+theme(legend.position ='none', axis.text.y =element_blank(), plot.title =element_text(face='bold', size=rel(1.5)), plot.subtitle =element_textbox(), plot.caption =element_textbox())
Show code
penguin_ternary_viz<-penguins_complete%>%ggtern(aes(x =scale(bill_length_mm), y =scale(body_mass_g), z =scale(flipper_length_mm), color=species, fill=species))+geom_point(aes(fill=species), shape =21, size =3, alpha =.5)+scale_color_manual(values =peng_cols)+scale_fill_manual(values =peng_cols)+labs(title ='Relationship between bill length, body mass, and flipper length', subtitle =glue("for <span style='color:maroon1'>**Gentoo**</span>, <span style='color:seagreen3'>**Chinstrap**</span>, and <span style='color:cornflowerblue'>**Adelie**</span> penguins"), x='', y='', z='', caption='Tidy Tuesday Week 31 (2020)<br>**Source**: {palmerpenguins}')+Larrowlab("Bill length (0-100 scaled)\n")+Tarrowlab("Body mass (0-100 scaled)\n")+Rarrowlab("\nFlipper length (0-100 scaled)")+my_theme+theme(tern.axis.arrow.show =TRUE, plot.title =element_text(face='bold', size=rel(1.5), lineheight =1.5), tern.axis.text =element_text(size =rel(1.5)), legend.position ='none', plot.subtitle =element_textbox(), plot.caption =element_textbox())
7. Save
Show code
# RIDGEPLOTggsave( filename =glue("tt_{tt_year}_{tt_week}_ridge.png"), plot =pen_mass_by_island_ridgeplot_viz, width =10, height =6, units ="in", dpi =320)# make thumbnail for pagemagick::image_read(glue("tt_{tt_year}_{tt_week}_ridge.png"))%>%magick::image_resize(geometry ="400")%>%magick::image_write(glue("tt_{tt_year}_{tt_week}_ridge_thumbnail.png"))# TERNARYggsave( filename =glue("tt_{tt_year}_{tt_week}_ternary.png"), plot =penguin_ternary_viz, width =9, height =9, units ="in", dpi =320)# make thumbnail for pagemagick::image_read(glue("tt_{tt_year}_{tt_week}_ternary.png"))%>%magick::image_resize(geometry ="400")%>%magick::image_write(glue("tt_{tt_year}_{tt_week}_ternary_thumbnail.png"))