Push the `knit` button!


```{r setup, child="exercise-setup.Rmd", eval = file.exists("exercise-setup.Rmd")}
```

```{r, include = FALSE}
knitr::opts_chunk$set(
  fig.path = "images/part2-exercise-01/",
  class.source = "solution",
  message = FALSE,
  error = FALSE,
  warning = FALSE,
  fig.height = 3,
  fig.width = 10
)
```

```{r pkgs, message = FALSE, warning = FALSE}
library(tidyverse) # contains ggplot2, dplyr, tidyr, etc
library(palmerpenguins)
library(plotly)
library(GGally)
```


### Exercise 1.1: Interactive scatterplot

Make a scatterplot of `flipper length` by `body_mass_g` coloured by the three `species` of penguins. Add a tooltip that labels the points by variable values and the species.

```{r part2-exercise-01, echo = T, class = "target"}
p1 <- ggplot(penguins, 
             aes(x=flipper_length_mm, 
                 y=body_mass_g, 
                 colour=species)) +
  geom_point() 
ggplotly(p1, width=400, height=300)
```

### Exercise 1.2: Interactive histogram

Make a histogram of `flipper_length_mm` facetted by `species` and sex`, paying attention to remove the missing values. Add a tooltip that contains the count, flipper length of minimum of the bin. 

```{r part2-exercise-02, echo = T, class = "target"}
p2 <- penguins %>%
  filter(!is.na(sex)) %>%
  ggplot(aes(x=flipper_length_mm)) +
    geom_histogram(binwidth=5) + 
  facet_grid(sex~species) 
ggplotly(p2, width=600, height=400)
```

### Exercise 1.3: Scatterplot matrix

Make a scatterplot matrix of four variables for the Gentoo penguins, coloured by sex. Pay attention to removing missing values. 

```{r part2-exercise-03, echo = T, class = "target"}
gentoo <- penguins %>%
  filter(species == "Gentoo") %>%
  filter(!is.na(sex)) %>%
    rename(bl = bill_length_mm,
         bd = bill_depth_mm,
         fl = flipper_length_mm,
         bm = body_mass_g) %>%
  select(bl, bd, fl, bm, sex)
gentoo_splom <- ggpairs(gentoo, columns=1:4, 
                 aes(color = sex)) +
  theme(axis.text = element_blank())
ggplotly(gentoo_splom, width=500, height=500) %>%
  highlight(on="plotly_selected")
```

### Exercise 1.4: Sign up for a shinyapps.io account

In preparation for lesson 3:

Sign up for an account on https://www.shinyapps.io

Authenticate your account

Install the library rsconnect (this is the part that may require admin access to your machine)
