forked from AdamWilsonLabEDU/2024-geo511-spatial-data-science-case-studies-geo511_casestudy_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
``` |