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")

These exercises will explore the penguins data set using histograms.

head(penguins)

Exercise 1

Produce a histogram of the bill depth.


hist(penguins$bill_depth_mm)
ex() %>% {
  check_error(.)
  check_function(., "hist") %>% check_arg(., "x") %>% check_equal(.)
}

Exercise 2

Produce a histogram of the flipper length - make the bars of the histogram blue:


hist(penguins$flipper_length_mm, col="blue")
ex() %>% {
  check_error(.)
  check_function(., "hist") %>% {
    check_arg(., "x") %>% check_equal(.)
    check_arg(., "col", arg_not_specified_msg="use the col argument to specify the bar colour")
  }
}

Exercise 3

The previous histogram has two "bumps" (the technical term for this is multimodal). Produce a histogram of flipper length by species:

require(plotrix)
require(plotrix)

multhist(split(penguins$flipper_length_mm, penguins$species), legend.text=TRUE)
ex() %>% {
  check_error(.)
  check_function(., "multhist") %>% {
    check_arg(., "x") %>% check_equal(., incorrect_msg="Use split() to separate the column you wish to plot by the grouping variable")
    check_arg(., "legend.text", arg_not_specified_msg="Interpretation will be a lot easier with a legend") %>% check_equal(., incorrect_msg="Set legend.text=TRUE to add a legend")
  }
}

success_msg("Great Work! You can see that the second mode is gentoo penguins - it is often the case with multimodal data that the difference in modes is caused by some underlying grouping.")


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