Skip to content

Commit

Permalink
case study 12
Browse files Browse the repository at this point in the history
  • Loading branch information
jingmiao7 committed Nov 19, 2024
1 parent 45bea51 commit eb76b5a
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions week_12/case_study_12.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,72 @@
---
title: "Case Study 12"
author: Your Name
date: August 1, 2020
author: Jing Miao
date: Nov 19, 2024
output: github_document
editor_options:
markdown:
wrap: 72
---


# install and load necessary packages

```{r}
#install.packages("htmlwidgets") #install.packages("widgetframe")
#install.packages("xts") #install.packages("dygraphs")
#install.packages("openmeteo")
```

```{r, , message=FALSE, warning=FALSE}
library(tidyverse)
library(htmlwidgets)
library(widgetframe)
library(xts)
library(dygraphs)
library(openmeteo)
```

# download the weather dataset

```{r}
d <- weather_history(c(43.00923265935055, -78.78494250958327),start =
"2023-01-01",end=today(),
daily=list("temperature_2m_max","temperature_2m_min","precipitation_sum"))%>%
mutate(daily_temperature_2m_mean=(daily_temperature_2m_max+daily_temperature_2m_min)/2)
```

# convert the data into xts

```{r}
weather <- as.xts(d, order.by=d$date)
```

# plot

## the daily max temperature

```{r}
dygraph(weather[, "daily_temperature_2m_max"], main = "Daily Maximum
Temperature in Buffalo, NY") %>% dyRangeSelector(dateWindow =
c("2023-01-01", "2024-10-31"))
```

## the daily precipitation

```{r}
dygraph(weather[, "daily_precipitation_sum"], main = "Daily
Precipitation in Buffalo, NY") %>% dyRangeSelector(dateWindow =
c("2023-01-01", "2024-10-31"))
```

## the weather in one graph

```{r}
dygraph(weather, main = "Daily Weather in Buffalo, NY") %>%
dyRangeSelector(dateWindow = c("2023-01-01", "2024-10-31"))%>%
dySeries("daily_temperature_2m_max", label = "Max Temp")%>%
dySeries("daily_temperature_2m_min", label = "Min Temp")%>%
dySeries("daily_temperature_2m_mean", label = "Average Temp")%>%
dySeries("daily_precipitation_sum", label = "Precipitation")
```

0 comments on commit eb76b5a

Please sign in to comment.