Module 01
Intro to RStudio
install.packages(“palmerpenguins”)
library("palmerpenguins")
summary(penguins)
## species island bill_length_mm bill_depth_mm
## Adelie :152 Biscoe :168 Min. :32.10 Min. :13.10
## Chinstrap: 68 Dream :124 1st Qu.:39.23 1st Qu.:15.60
## Gentoo :124 Torgersen: 52 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 female:165 Min. :2007
## 1st Qu.:190.0 1st Qu.:3550 male :168 1st Qu.:2007
## Median :197.0 Median :4050 NA's : 11 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
View(penguins)
library(ggplot2)
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) + geom_point(aes(color = species))
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

————————————————————————————————————————————————-
Module 02
Operators and calculations
# our first calculations
quarter_1_sales <- 35657.98
quarter_2_sales <- 43810.55
midyear_sales <- quarter_1_sales + quarter_2_sales
midyear_sales
## [1] 79468.53
yearend_sales <- midyear_sales * 2
yearend_sales
## [1] 158937.1
| # Welcome to the tidyverse |
| install.packages(“tidyverse”) |
r library("tidyverse") |
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.4 ✔ readr 2.1.5 ## ✔ forcats 1.0.0 ✔ stringr 1.5.1 ## ✔ lubridate 1.9.3 ✔ tibble 3.2.1 ## ✔ purrr 1.0.2 ✔ tidyr 1.3.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 |
Use pipes to nest code
- ToothGrowth Dataset case study
data("ToothGrowth")
View(ToothGrowth)
install.packages(“dplyr”)
filtered_tg <- filter(ToothGrowth, dose == 0.5)
filtered_tg
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
## 7 11.2 VC 0.5
## 8 11.2 VC 0.5
## 9 5.2 VC 0.5
## 10 7.0 VC 0.5
## 11 15.2 OJ 0.5
## 12 21.5 OJ 0.5
## 13 17.6 OJ 0.5
## 14 9.7 OJ 0.5
## 15 14.5 OJ 0.5
## 16 10.0 OJ 0.5
## 17 8.2 OJ 0.5
## 18 9.4 OJ 0.5
## 19 16.5 OJ 0.5
## 20 9.7 OJ 0.5
arrange(filtered_tg, len)
## len supp dose
## 1 4.2 VC 0.5
## 2 5.2 VC 0.5
## 3 5.8 VC 0.5
## 4 6.4 VC 0.5
## 5 7.0 VC 0.5
## 6 7.3 VC 0.5
## 7 8.2 OJ 0.5
## 8 9.4 OJ 0.5
## 9 9.7 OJ 0.5
## 10 9.7 OJ 0.5
## 11 10.0 VC 0.5
## 12 10.0 OJ 0.5
## 13 11.2 VC 0.5
## 14 11.2 VC 0.5
## 15 11.5 VC 0.5
## 16 14.5 OJ 0.5
## 17 15.2 OJ 0.5
## 18 16.5 OJ 0.5
## 19 17.6 OJ 0.5
## 20 21.5 OJ 0.5
arrange(filter(ToothGrowth, dose == 0.5), len)
## len supp dose
## 1 4.2 VC 0.5
## 2 5.2 VC 0.5
## 3 5.8 VC 0.5
## 4 6.4 VC 0.5
## 5 7.0 VC 0.5
## 6 7.3 VC 0.5
## 7 8.2 OJ 0.5
## 8 9.4 OJ 0.5
## 9 9.7 OJ 0.5
## 10 9.7 OJ 0.5
## 11 10.0 VC 0.5
## 12 10.0 OJ 0.5
## 13 11.2 VC 0.5
## 14 11.2 VC 0.5
## 15 11.5 VC 0.5
## 16 14.5 OJ 0.5
## 17 15.2 OJ 0.5
## 18 16.5 OJ 0.5
## 19 17.6 OJ 0.5
## 20 21.5 OJ 0.5
filtered_toothgrowth <- ToothGrowth %>%
filter(dose == 0.5) %>%
arrange(len)
filtered_toothgrowth
## len supp dose
## 1 4.2 VC 0.5
## 2 5.2 VC 0.5
## 3 5.8 VC 0.5
## 4 6.4 VC 0.5
## 5 7.0 VC 0.5
## 6 7.3 VC 0.5
## 7 8.2 OJ 0.5
## 8 9.4 OJ 0.5
## 9 9.7 OJ 0.5
## 10 9.7 OJ 0.5
## 11 10.0 VC 0.5
## 12 10.0 OJ 0.5
## 13 11.2 VC 0.5
## 14 11.2 VC 0.5
## 15 11.5 VC 0.5
## 16 14.5 OJ 0.5
## 17 15.2 OJ 0.5
## 18 16.5 OJ 0.5
## 19 17.6 OJ 0.5
## 20 21.5 OJ 0.5
filtered_toothgrowth <- ToothGrowth %>%
filter(dose == 0.5) %>%
group_by(supp) %>%
summarize(mean_len = mean(len, na.rm = T), .group = "drop")
filtered_toothgrowth
## # A tibble: 2 × 3
## supp mean_len .group
## <fct> <dbl> <chr>
## 1 OJ 13.2 drop
## 2 VC 7.98 drop
————————————————————————————————————————————————-
Module 03
Working with data frames
- Diamond Dataset case study
library("ggplot2")
data("diamonds")
View(diamonds)
head(diamonds)
## # A tibble: 6 × 10
## carat cut color clarity depth table price x y z
## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43
## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31
## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
## 4 0.29 Premium I VS2 62.4 58 334 4.2 4.23 2.63
## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75
## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
str(diamonds)
## tibble [53,940 × 10] (S3: tbl_df/tbl/data.frame)
## $ carat : num [1:53940] 0.23 0.21 0.23 0.29 0.31 0.24 0.24 0.26 0.22 0.23 ...
## $ cut : Ord.factor w/ 5 levels "Fair"<"Good"<..: 5 4 2 4 2 3 3 3 1 3 ...
## $ color : Ord.factor w/ 7 levels "D"<"E"<"F"<"G"<..: 2 2 2 6 7 7 6 5 2 5 ...
## $ clarity: Ord.factor w/ 8 levels "I1"<"SI2"<"SI1"<..: 2 3 5 4 2 6 7 3 4 5 ...
## $ depth : num [1:53940] 61.5 59.8 56.9 62.4 63.3 62.8 62.3 61.9 65.1 59.4 ...
## $ table : num [1:53940] 55 61 65 58 58 57 57 55 61 61 ...
## $ price : int [1:53940] 326 326 327 334 335 336 336 337 337 338 ...
## $ x : num [1:53940] 3.95 3.89 4.05 4.2 4.34 3.94 3.95 4.07 3.87 4 ...
## $ y : num [1:53940] 3.98 3.84 4.07 4.23 4.35 3.96 3.98 4.11 3.78 4.05 ...
## $ z : num [1:53940] 2.43 2.31 2.31 2.63 2.75 2.48 2.47 2.53 2.49 2.39 ...
colnames(diamonds)
## [1] "carat" "cut" "color" "clarity" "depth" "table" "price"
## [8] "x" "y" "z"
library(tidyverse)
mutate(diamonds, carat_2=carat*100)
## # A tibble: 53,940 × 11
## carat cut color clarity depth table price x y z carat_2
## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43 23
## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31 21
## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31 23
## 4 0.29 Premium I VS2 62.4 58 334 4.2 4.23 2.63 29
## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75 31
## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48 24
## 7 0.24 Very Good I VVS1 62.3 57 336 3.95 3.98 2.47 24
## 8 0.26 Very Good H SI1 61.9 55 337 4.07 4.11 2.53 26
## 9 0.22 Fair E VS2 65.1 61 337 3.87 3.78 2.49 22
## 10 0.23 Very Good H VS1 59.4 61 338 4 4.05 2.39 23
## # ℹ 53,930 more rows
| # Organize your data |
r library(tidyverse) |
r penguins %>% arrange(bill_length_mm) |
## # A tibble: 344 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Adelie Dream 32.1 15.5 188 3050 ## 2 Adelie Dream 33.1 16.1 178 2900 ## 3 Adelie Torgersen 33.5 19 190 3600 ## 4 Adelie Dream 34 17.1 185 3400 ## 5 Adelie Torgersen 34.1 18.1 193 3475 ## 6 Adelie Torgersen 34.4 18.4 184 3325 ## 7 Adelie Biscoe 34.5 18.1 187 2900 ## 8 Adelie Torgersen 34.6 21.1 198 4400 ## 9 Adelie Torgersen 34.6 17.2 189 3200 ## 10 Adelie Biscoe 35 17.9 190 3450 ## # ℹ 334 more rows ## # ℹ 2 more variables: sex <fct>, year <int> |
r penguins %>% arrange(-bill_length_mm) |
## # A tibble: 344 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> <int> <int> ## 1 Gentoo Biscoe 59.6 17 230 6050 ## 2 Chinstrap Dream 58 17.8 181 3700 ## 3 Gentoo Biscoe 55.9 17 228 5600 ## 4 Chinstrap Dream 55.8 19.8 207 4000 ## 5 Gentoo Biscoe 55.1 16 230 5850 ## 6 Gentoo Biscoe 54.3 15.7 231 5650 ## 7 Chinstrap Dream 54.2 20.8 201 4300 ## 8 Chinstrap Dream 53.5 19.9 205 4500 ## 9 Gentoo Biscoe 53.4 15.8 219 5500 ## 10 Chinstrap Dream 52.8 20 205 4550 ## # ℹ 334 more rows ## # ℹ 2 more variables: sex <fct>, year <int> |
r penguins2 <- penguins %>% arrange(-bill_length_mm) |
r View(penguins2) |
r penguins %>% group_by(island) %>% drop_na() %>% summarize(mean_bill_length_mm = mean(bill_length_mm)) |
## # A tibble: 3 × 2 ## island mean_bill_length_mm ## <fct> <dbl> ## 1 Biscoe 45.2 ## 2 Dream 44.2 ## 3 Torgersen 39.0 |
r penguins %>% group_by(island) %>% drop_na() %>% summarize(max_bill_length_mm = max(bill_length_mm)) |
## # A tibble: 3 × 2 ## island max_bill_length_mm ## <fct> <dbl> ## 1 Biscoe 59.6 ## 2 Dream 58 ## 3 Torgersen 46 |
r penguins %>% group_by(species, island) %>% drop_na() %>% summarize(max_bl = max(bill_length_mm), mean_bl = mean(bill_length_mm)) |
## `summarise()` has grouped output by 'species'. You can override using the ## `.groups` argument. |
## # A tibble: 5 × 4 ## # Groups: species [3] ## species island max_bl mean_bl ## <fct> <fct> <dbl> <dbl> ## 1 Adelie Biscoe 45.6 39.0 ## 2 Adelie Dream 44.1 38.5 ## 3 Adelie Torgersen 46 39.0 ## 4 Chinstrap Dream 58 48.8 ## 5 Gentoo Biscoe 59.6 47.6 |
r penguins %>% filter(species == "Adelie") |
## # A tibble: 152 × 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 ## 7 Adelie Torgersen 38.9 17.8 181 3625 ## 8 Adelie Torgersen 39.2 19.6 195 4675 ## 9 Adelie Torgersen 34.1 18.1 193 3475 ## 10 Adelie Torgersen 42 20.2 190 4250 ## # ℹ 142 more rows ## # ℹ 2 more variables: sex <fct>, year <int> |
Transforming data
id <- c(1:10)
name <- c("John Mendes", "Rob Stewart", "Rachel Abrahamson", "Christy Hickman", "Johnson Harper", "Candace Miller", "Carlson Landy", "Pansy Jordan", "Darius Berry", "Claudia Garcia")
job_title <- c("Professional", "Programmer", "Management", "Clerical", "Developer", "Programmer", "Management", "Clerical", "Developer", "Programmer")
employee <- data.frame(id, name, job_title)
print(employee)
## id name job_title
## 1 1 John Mendes Professional
## 2 2 Rob Stewart Programmer
## 3 3 Rachel Abrahamson Management
## 4 4 Christy Hickman Clerical
## 5 5 Johnson Harper Developer
## 6 6 Candace Miller Programmer
## 7 7 Carlson Landy Management
## 8 8 Pansy Jordan Clerical
## 9 9 Darius Berry Developer
## 10 10 Claudia Garcia Programmer
separate(employee, name, into = c('first_name', 'last_name'), sep = ' ')
## id first_name last_name job_title
## 1 1 John Mendes Professional
## 2 2 Rob Stewart Programmer
## 3 3 Rachel Abrahamson Management
## 4 4 Christy Hickman Clerical
## 5 5 Johnson Harper Developer
## 6 6 Candace Miller Programmer
## 7 7 Carlson Landy Management
## 8 8 Pansy Jordan Clerical
## 9 9 Darius Berry Developer
## 10 10 Claudia Garcia Programmer
first_name <- c("John", "Rob", "Rachel", "Christy", "Johnson", "Candace", "Carlson", "Pansy", "Darius", "Claudia")
last_name <- c("Mendes", "Stewart", "Abrahamson", "Hickman", "Harper", "Miller", "Landy", "Jordan", "Berry", "Garcia")
job_title <- c("Professional", "Programmer", "Management", "Clerical", "Developer", "Programmer", "Management", "Clerical", "Developer", "Programmer")
employee <- data.frame(id, first_name, last_name, job_title)
print(employee)
## id first_name last_name job_title
## 1 1 John Mendes Professional
## 2 2 Rob Stewart Programmer
## 3 3 Rachel Abrahamson Management
## 4 4 Christy Hickman Clerical
## 5 5 Johnson Harper Developer
## 6 6 Candace Miller Programmer
## 7 7 Carlson Landy Management
## 8 8 Pansy Jordan Clerical
## 9 9 Darius Berry Developer
## 10 10 Claudia Garcia Programmer
unite(employee, 'name', first_name, last_name, sep = ' ')
## id name job_title
## 1 1 John Mendes Professional
## 2 2 Rob Stewart Programmer
## 3 3 Rachel Abrahamson Management
## 4 4 Christy Hickman Clerical
## 5 5 Johnson Harper Developer
## 6 6 Candace Miller Programmer
## 7 7 Carlson Landy Management
## 8 8 Pansy Jordan Clerical
## 9 9 Darius Berry Developer
## 10 10 Claudia Garcia Programmer
View(penguins)
penguins %>%
mutate(body_mass_kg = body_mass_g/1000)
## # A tibble: 344 × 9
## 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
## 7 Adelie Torgersen 38.9 17.8 181 3625
## 8 Adelie Torgersen 39.2 19.6 195 4675
## 9 Adelie Torgersen 34.1 18.1 193 3475
## 10 Adelie Torgersen 42 20.2 190 4250
## # ℹ 334 more rows
## # ℹ 3 more variables: sex <fct>, year <int>, body_mass_kg <dbl>
penguins %>%
mutate(body_mass_kg = body_mass_g/1000, flipper_length_m = flipper_length_mm/1000)
## # A tibble: 344 × 10
## 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
## 7 Adelie Torgersen 38.9 17.8 181 3625
## 8 Adelie Torgersen 39.2 19.6 195 4675
## 9 Adelie Torgersen 34.1 18.1 193 3475
## 10 Adelie Torgersen 42 20.2 190 4250
## # ℹ 334 more rows
## # ℹ 4 more variables: sex <fct>, year <int>, body_mass_kg <dbl>,
## # flipper_length_m <dbl>
| # The bias function |
| install.packages(“SimDesign”) |
r library(SimDesign) |
| install.packages(“Metrics”) |
r library("Metrics") |
## ## Attaching package: 'Metrics' |
## The following object is masked from 'package:SimDesign': ## ## bias |
r find("bias") |
## [1] "package:Metrics" "package:SimDesign" |
r actual_temp <- c(68.3, 70, 72.4, 71, 67, 70) predicted_temp <- c(67.9, 69, 71.5, 70, 67, 69) bias(actual_temp, predicted_temp) |
## [1] 0.7166667 |
| * Games store case study |
r actual_sales <- c(150, 203, 137, 247, 116, 287) predicted_sales <- c(200, 300, 150, 250, 150, 300) bias(actual_sales, predicted_sales) |
## [1] -35 |
| # Enhancing visualizations in R |
r library(ggplot2) library(palmerpenguins) |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, shape = species)) |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, shape = species, colour = species)) |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, shape = species, colour = species, size = species)) |
## Warning: Using size for a discrete variable is not advised. |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, alpha = species)) |
## Warning: Using alpha for a discrete variable is not advised. |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g),color = "purple") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
Doing more with ggplot
library(ggplot2)
library(palmerpenguins)
ggplot(data = penguins) +
geom_smooth(mapping = aes(x=flipper_length_mm, y=body_mass_g))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_smooth()`).

ggplot(data = penguins) +
geom_smooth(mapping = aes(x=flipper_length_mm, y=body_mass_g)) +
geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = penguins) +
geom_smooth(mapping = aes(x=flipper_length_mm, y=body_mass_g, linetype = species))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_smooth()`).

ggplot(data = penguins) +
geom_jitter(mapping = aes(x=flipper_length_mm, y=body_mass_g))
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(data = diamonds) +
geom_bar(mapping = aes(x=cut))

ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, colour = cut))

ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut))

ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity))

| # Annotation layer |
| * Palmer Penguins case study |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") + annotate("text", x=220, y=3500, label = "The Gentoos are the largest") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") + annotate("text", x=220, y=3500, label = "The Gentoos are the largest", color = "purple") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") + annotate("text", x=220, y=3500, label = "The Gentoos are the largest", color = "purple", fontface="bold", size=4.5) |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") + annotate("text", x=220, y=3500, label = "The Gentoos are the largest", color = "purple", fontface="bold", size=4.5, angle=25) |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
r P <- ggplot(data = penguins) + geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, colour = species)) + labs(title = "Palmer Penguins: Body Mass vs. Flipper Length", subtitle = "Sample of Three Penguin Species", caption = "Data collected by Dr.Kriten Gorman") |
r P + annotate("text", x=220, y=3500, label = "The Gentoos are the largest") |
## Warning: Removed 2 rows containing missing values or values outside the scale range ## (`geom_point()`). |
 |
Saving your visualizations
library(ggplot2)
library(palmerpenguins)
ggplot(data = penguins) +
geom_point(mapping = aes(x=flipper_length_mm, y=body_mass_g, color = species)) +
facet_wrap(~species)
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggsave("Three Penguin Species.png")
## Saving 7 x 5 in image
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).