library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag(): dplyr, stats
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(ggridges)
library(ggjoy)
## The ggjoy package has been deprecated. Please switch over to the
## ggridges package, which provides the same functionality. Porting
## guidelines can be found here:
## https://github.com/clauswilke/ggjoy/blob/master/README.md
load("D:/Downloads/olywthr.rdata")
In this assignment you will explore a few different ways to explore the variation in weather over a year. We will use the olywthr dataset.
Use all of the historical data to compute the probability of rain for each day of the year. Do a simple scatterplot graph to portray the results as a forecast for calendar 2018. You should filter out all of the leapdays in history since there is no February 29 in 2018.
olywthr %>%
filter(!(mo == 2 & dy == 29)) %>%
group_by(mo, dy) %>%
summarise(prain = mean(PRCP > 0, na.rm = TRUE)) %>%
ungroup() -> cal18
cal18$day <- seq.int(nrow(cal18))
rainy18 <-ggplot(cal18, aes(day, prain)) +
geom_point()
rainy18
Add a loess smoother to the scatterplot. Select a good value of the span argument.
rainy18 +
geom_smooth(span = 0.2) #higher span argument restricts flexibility of loess curve
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#span = 0.2 seems like a good value for this graphic
Create density plots for the value of prain and use facetting to show each month separately.
cal18 %>% ggplot(aes(prain)) +
geom_histogram() +
facet_wrap(~mo)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Read the material at https://github.com/clauswilke/ggridges and then create a joyplot or (ridgeline plot) as an alternative to the facet by month.
ggplot(cal18, aes(x = mo, y = prain, height = prain)) +
geom_ridgeline()
ggplot(cal18, aes(x = mo, y = prain, height = prain, group = mo)) +
geom_joy(stat = "identity", scale = 3)