Penguin Plots: Basic Analysis Practice

Creating Plots Using Palmer Penguin Data

Formatting Included:
  • Title
  • Subtitle
  • Caption
  • Annotate()

Notes: load ggplot 2, tidyverse and penguins

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.1.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.1.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.5     v dplyr   1.0.9
## v tidyr   1.1.4     v stringr 1.4.0
## v readr   2.0.2     v forcats 0.5.1
## v purrr   0.3.4
## Warning: package 'dplyr' was built under R version 4.1.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(palmerpenguins)  
## Warning: package 'palmerpenguins' was built under R version 4.1.3

Plot variables are flipper length against body mass

Create a Plot and add label with title

ggplot(data=penguins) + geom_point(mapping=aes(x=flipper_length_mm, y=body_mass_g, color=species)) + labs(title="Palmer Penguins: Body Mass Vs. Flipper Length")
## Warning: Removed 2 rows containing missing values (geom_point).

Add a subtitle to plot

ggplot(data=penguins) + geom_point(mapping=aes(x=flipper_length_mm, y=body_mass_g, color=species)) + labs(title="Palmer Penguins: Body Mass Vs. Flipper Length", subtitle = "Sample of Three Penguin Species")
## Warning: Removed 2 rows containing missing values (geom_point).

Add a caption to plot, to cite where data came from

ggplot(data=penguins) + geom_point(mapping=aes(x=flipper_length_mm, y=body_mass_g, color=species)) + labs(title="Palmer Penguins: Body Mass Vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr. Kristen Gorman, 2007-2009") 
## Warning: Removed 2 rows containing missing values (geom_point).

Use annotate() func to highlight data from the Gentoo penguins, change color of text, font bold and size of text, angle text to 25 degrees

ggplot(data=penguins) + geom_point(mapping=aes(x=flipper_length_mm, y=body_mass_g, color=species)) + labs(title="Palmer Penguins: Body Mass Vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr. Kristen Gorman, 2007-2009")+ annotate("text", x=220, y=3500, label="The Gentoos are the largest", color="pink", fontface="bold", size=4.5, angle=25) 
## Warning: Removed 2 rows containing missing values (geom_point).