```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Exercises

These exercises are intended for you to practice the skills that you have learned this morning with Carolyn and Shannon, and expand on how to display this information directly from the analysis file using R Markdown.

Each code chunk will relate to a question. We make suggestions for variable names where they need to be created. 

It might be advantageous for you to work in groups to solve the problems. You will be given a set time to solve each of these problems, the solution will then be given and then we will move onto the next.

Where you see the text `NULL`, replace it with the executable code that you wish to run to achieve the tasks set out

### Question 1

We will be using the Tidyverse packages and the data file `"metal_bands_2017.csv"`. The original version of this data can be found on [Kaggle](https://www.kaggle.com/mrpantherson/metal-by-nation), but we have provided you with the file to download from [SiM link](unknown-link).

In the following code chunk load Tidyverse and load the data file for the tasks ahead.

```{r lib_read}

# HINT: library(???)

band_dat <- NULL

```

### Question 2

As you can see the styles of metal are combined into the same cell, much the same as the eye descriptions were. This is less than optimal. They are separated by commas, however, which allows them to be easily split.

Separate these out into 4 different columns (s1, s2, s3, s4), dropping the extra.

```{r separating}
band_separate <- NULL
```

### Question 3

The data is still not tidy, as we have multiple "observations" (more than one style descriptor) on each row.

Turn the data from this wide format into long format, using the `gather()` function with the arguments `key = "style_n"` and `value = "style"`.

```{r gathering}
band_gather <- NULL
```

### Question 4

As you can see, not all bands has 4 or more style descriptions, leaving a lot of NAs in our data.

Filter out the rows that have styles of NA.

```{r filtering}
band_filtered <- NULL
```

### Question 5

To remove differences caused by capitalisations we should change style to lower case. We should also remove any white space before and after the descriptors.

Let us also change the split column... bands with "-" here are still active. We want to replace this value with the current year. A further problem is that the column is read by R as character information, not numeric.

```{r mutating}
band_mutated <- NULL
```

### Question 6

Group the data by style and summarise it by counting the number of bands with each style.

```{r grouping_summarising}
band_style_grouped <- NULL

band_style_summary <- NULL
```

### Question 7

Now we want to find out what the top 10 styles of metal are. This will require us to arrange the summarised data in descending order and retain only the top 10 rows.

```{r arranged_top_10}

```

### Question 8

Put this in a graph like you did before with the eyes data set. 

You might want to pick a more "metal" colour palette than "spectral". To see the palettes available load `library(RColorBrewer)` then `display.brewer.all()` in the console.

Using the argument `direction = -1` within `scale_fill_brewer()` will reverse the colour scale making "black" metal actually black.

Change the x and y axes using `labs()` to suitable names.

```{r ggplot}

```

### Question 9

Stop now and knit the file. 

It looks messy, right?

Open a new R Markdown file, delete the example that is given and "pipe" the results from questions 1-7 together in the first chunk, putting it into a variable called top_10_new.

Compare top_10 and top_10_new, they should be the same.

If we have yet to cover pipes, we will go over this as one large group.

### Question 10

Output `top_10_new` in a table using `knitr::kable` using inline code. Hide the code from question 9.

Recreate the graph too, with code hidden but output visible, adding a `fig.cap`.

Compare the new knitted markdown with the old one. Much more presentable, yeah?