library(learnr)
library(testwhat)
knitr::opts_chunk$set(echo = FALSE, message=FALSE)
tutorial_options(exercise.timelimit = 60, exercise.checker=testwhat::testwhat_learnr)

require(tidyverse)
penguins<- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-28/penguins.csv")
penguins<- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-28/penguins.csv")
penguins %>% mutate(year=as.factor(year)) -> penguins

We are going to use the penguins data to produce a variety of box plots using ggplot.

head(penguins)

Exercise 1

Produce a box plot showing body mass:


ggplot(penguins) +
  geom_boxplot(aes(body_mass_g))
ex() %>% {
  check_error(.)
  check_function(., "geom_boxplot") %>% check_arg(., "mapping") %>% check_equal(.)
}

Exercise 2

Produce a box plot that will compare the distribution of body weight by year (you should not separate the groups using colour):


penguins %>%
  ggplot() + 
  geom_boxplot(aes(x=year, y=body_mass_g))
ex() %>% {
  check_error(.)
  check_function(., "geom_boxplot") %>% check_arg(., "mapping") %>% check_equal(.)
}

Exercise 3

Produce a boxplot that will describe the distribution of body mass for each species within each year. The observations within a species should appear next to one another.


penguins %>%
  ggplot() + 
  geom_boxplot(aes(x=species, y=body_mass_g, fill=year))
ex() %>% {
  check_error(.)
  check_function(., "geom_boxplot") %>% check_arg(., "mapping") %>% check_equal(.)
}


kate-pyper/MM916ProgrammingExercises documentation built on Oct. 15, 2020, 10:40 p.m.