Setup

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(googleVis)
## Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
## 
## Welcome to googleVis version 0.6.2
## 
## Please read Google's Terms of Use
## before you start using the package:
## https://developers.google.com/terms/
## 
## Note, the plot method of googleVis will by default use
## the standard browser to display its output.
## 
## See the googleVis package vignettes for more details,
## or visit http://github.com/mages/googleVis.
## 
## To suppress this message use:
## suppressPackageStartupMessages(library(googleVis))
op <- options(gvis.plot.tag='chart')
load("~/Dropbox/RProjects/Oly Weather/olywthr.rdata")

Background

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.

Problem 1

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 %>% 
  group_by(mo,dy) %>% 
  filter(!(mo == 2 & dy == 29)) %>% 
  summarise(prain = mean(PRCP > 0)) %>% 
  ungroup() %>% 
  mutate(date = make_date(2018,mo,dy)) -> rainprob

  rainprob %>% ggplot(aes(x=date,y=prain)) + 
    geom_point()

Problem 2

Add a loess smoother to the scatterplot. Select a good value of the adjust argument.

 rainprob %>% ggplot(aes(x=date,y=prain)) + 
    geom_point() +
    geom_smooth(span=.2)
## `geom_smooth()` using method = 'loess'

Problem 3

Create density plots for the value of prain and use facetting to show each month separately.

 rainprob %>% ggplot(aes(x=prain)) + 
    geom_density() +
    facet_wrap(~mo)

Problem 4

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.

rainprob %>% ggplot(aes(x=prain,y=factor(mo))) + geom_density_ridges()
## Picking joint bandwidth of 0.0188

Problem 5

Cal <- gvisCalendar(rainprob, 
                    datevar="date", 
                    numvar="prain",
                    options=list(
                      title="Probability of Rain in Olympia",
                      height=320,
                      calendar="{yearLabel: { fontName: 'Times-Roman',
                               fontSize: 32, color: '#1A8763', bold: true},
                               cellSize: 10,
                               cellColor: { stroke: 'red', strokeOpacity: 0.2 },
                               focusedCellColor: {stroke:'red'}}")
)
plot(Cal)