---
title: "Lab 18: Working one table verbs and pipes"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(fig.height = 5)
knitr::opts_chunk$set(fig.width = 8.5)
knitr::opts_chunk$set(out.width = "100%")
knitr::opts_chunk$set(dpi = 300)
library(readr)
library(ggplot2)
library(dplyr)
library(viridis)
library(smodels)
theme_set(theme_minimal())
```
## Storm dataset again
Today, we are going to look at a NASA weather dataset. This particular
one contains information about Atlantic storms. Read it in with the
following:
```{r}
storms <- read_csv("https://statsmaths.github.io/stat_data/storms.csv")
```
It may also be useful to have a dataset giving the borders of countries:
```{r}
borders <- read_csv("https://statsmaths.github.io/stat_data/nasa_borders.csv")
```
Using the arrange function, sort the dataset in descending order of wind
speed. Which two storms had the largest wind speeds:
```{r}
```
Create a new variable in the dataset called doy (day of year) defined
as the month plus the day divided by 32 minus 1.
```{r}
```
Create a scatter plot of wind speed as a function of doy. Use a pipe
to do this.
```{r}
```
Create a histogram of storms per year between 2000 and 2010 using the
filter function and a pipe.
```{r}
```
Create a dataset that consists only of tropical storms and construct a
histogram of wind speeds from this data.
```{r}
```
Using the summarize command, compute the mean, median, and 25%
percentile of wind speeds from all storms.
```{r}
```
Combine the prior function with a filter command to compute the mean,
median, and 25% percentile of wind speeds from all category 5 storms.
```{r}
```
Construct a scatter plot with longitude on the x-axis and latitude on
the y-axis of all storms. Use color to denote the category of the storm.
```{r}
```
Create a new variable `category_fct` that applies the function `factor`
to the category variable of the dataset `storms`. Use the `mutate` function
to do this.
```{r}
```
Construct a scatter plot with longitude on the x-axis and latitude on
the y-axis of all storms. Use color to denote the category of the storm,
but now use the `category_fct` variable.
```{r}
```
Using filter and pipes, construct a path plot with longitude and
latitude of all storms from 2015. Color the lines based on the name of the
storm.
```{r}
```
Add a `geom_path` layer to the prior plot that uses the borders data
and adds the aesthetic `group = group` (this stops it from connecting parts
of the map that are not connected).
```{r}
```
Repeat the prior plot but now: (1) only include latitude less than
40, (2) longitude less than -30, and (3) add `coord_cartesian(ylim = c(0, 40))`
to the plot. Again, use a pipe.
```{r}
```
Add points to the prior map where the size of the point is
determined by the category of storm. Make sure the color of the points
matches that of the storm name as well.
```{r}
```
Modify the prior plot so that we have all years from 2010 to
2015, the color is no longer given by the storm name (set it to "red" to
distinguish it from the borders), and use facets to facet by year. Note
that you will have to use the `group` aesthetic to get this to look right.
```{r}
```