---
title: "Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source: embed
code_folding: hide
theme: simplex
---
```{r setup, include=FALSE}
library(tidyverse)
library(plotly)
library(p8105.datasets)
library(flexdashboard)
library(rnoaa)
scale_colour_discrete = scale_colour_viridis_d
scale_fill_discrete = scale_fill_viridis_d
```
Back to [HOME](https://MefiMefi.github.io)
```{r read}
weather_df =
rnoaa::meteo_pull_monitors(
c("USW00094728", "USC00519397", "USS0023B17S"),
var = c("PRCP", "SNOW", "SNWD", "TMAX", "TMIN"),
date_min = "2017-01-01",
date_max = "2019-12-31") %>%
mutate(
name = recode(
id,
USW00094728 = "CentralPark_NY",
USC00519397 = "Waikiki_HA",
USS0023B17S = "Waterhole_WA"),
tmin = tmin / 10,
tmax = tmax / 10,
month = lubridate::floor_date(date, unit = "month")) %>%
mutate(
snow = case_when(
snow <0 ~0,
snow >= 0 ~snow)) %>%
select(name, id, everything())
```
## Plot 1
```{r plot_1}
plot_1 =
weather_df %>%
ggplot(aes(x = tmin, y = tmax, color = name)) +
geom_point(alpha = .2) +
geom_smooth(se = FALSE) +
facet_grid(. ~ name) +
labs(
title = "Max and Min Temperature associations (°C)",
x = "T-Min",
y = "T-Max",
color = "Name",
caption = "data from NOAA National Climatic Data Center"
)
ggplotly(plot_1)
```
Column {data-width=400}
-----------------------------------------------------------------------
## Plot 2
```{r plot_2}
plot_2 =
weather_df %>%
select(name, tmax, tmin) %>%
pivot_longer(
tmax:tmin,
names_to = "observation",
values_to = "temp") %>%
ggplot(aes(x = temp, fill = observation)) +
geom_density(alpha = .5) +
facet_grid(~name) +
labs(
title = "Max and Min Temperature Distributions)",
x = "Temperature",
y = "Frequency",
caption = "data from NOAA National Climatic Data Center"
)
ggplotly(plot_2)
```
Column {data-width=400}
-----------------------------------------------------------------------
## Plot 3
```{r plot_3}
plot_3 =
weather_df %>%
group_by(name, month) %>%
summarize(mean_tmax = mean(tmax)) %>%
ggplot(aes(x = month, y = mean_tmax, color = name)) +
geom_point() +
geom_line() +
labs(
title = "Trend of Mean of Max Temperature",
x = "Year",
y = "Mean T-Max(°C)",
color = "Name"
) +
scale_x_date(
date_breaks = "2 month"
) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))
ggplotly(plot_3)
```
Column {data-width=400}
-----------------------------------------------------------------------
## Plot 4
```{r plot_4}
plot_4 =
ggplot(weather_df, aes(x = name, y = tmax, fill = name)) + geom_violin(alpha = 0.5)+
labs(
title = "Distribution of Max Temperature",
x = "Location",
y = "T-Max(°C)",
color = "Name"
)
ggplotly(plot_4)
```
Column {data-width=400}
-----------------------------------------------------------------------