Column

Chart A:Minumum temperature vs Maximum temperature at January in different station from 2000 to 2010

Column

Chart B: Snowfall(mm) record in January from 2000 to 2010

Chart C: average precipitation(mm) in January from 2000 to 2010

---
title: "NY NOAA Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
    css: bootstrap.css
---

```{r setup, include=FALSE}
library(flexdashboard)
library(p8105.datasets)
library(tidyverse)
library(plotly)
```

```{r}
data("ny_noaa")

ny_noaa_tidy =
  ny_noaa %>% 
  janitor::clean_names() %>% 
  separate(col = date, into = c('year','month','day'), sep = "-" , convert = TRUE) %>% 
  mutate(
     month = month.name[month],
     prcp = prcp / 10,
     tmax = as.numeric(tmax),
     tmin = as.numeric(tmin),
     tmax = tmax / 10,
     tmin = tmin / 10
  ) 
```
Column {data-width=650}
-----------------------------------------------------------------------

### Chart A:Minumum temperature vs Maximum temperature at January in different station from 2000 to 2010

```{r}
ny_noaa_tidy %>% 
  filter(month == c("January")) %>% 
  filter(year > 2000) %>%
  group_by(id, year, month) %>%
  mutate(text_label = str_c("year: ", year, "\nid:", id)) %>% 
  plot_ly(x = ~tmin, y = ~tmax, text = ~text_label, color = ~year,
          alpha = .5, type = "scatter", mode = "markers",colors = "viridis") %>% 
  layout(title = "Minumum temperature vs Maximum temperature at January in different station from 2000 to 2010",
         xaxis = list(title = "Minimum Temperature C"),
         yaxis = list(title = "Maximum Temperature C")
  )
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B: Snowfall(mm) record in January from 2000 to 2010

```{r}
ny_noaa_tidy %>% 
  filter(month == c("January")) %>% 
  filter(0 < snow ) %>% 
  filter(snow < 100) %>%
  filter(year > 2000) %>% 
  mutate(
    year = as.factor(year)
  ) %>% 
  plot_ly(x = ~year, y = ~snow, color = ~year,
          alpha = .5, type = "box",colors = "viridis") %>% 
  layout(title = "Snowfall(mm) record in January from 2000 to 2010",
         xaxis = list(title = "year"),
         yaxis = list(title = "Snowfall(mm)")
  )
```

### Chart C: average precipitation(mm) in January from 2000 to 2010

```{r}
ny_noaa_tidy %>% 
  filter(month == c("January")) %>% 
  filter(year > 2000) %>% 
  group_by(year) %>% 
  summarize(
    prcp_average = mean(prcp, na.rm = TRUE)
  ) %>% 
  mutate(text_label = str_c("year: ", year, "\nprcp_average(mm):", prcp_average)) %>% 
  plot_ly(x = ~year, y = ~prcp_average, 
          alpha = .5, type = "scatter", text = ~text_label, mode = "lines",colors = "viridis") %>% 
  layout(title = "Average precipitation(mm) in January from 2000 to 2010",
         xaxis = list(title = "year"),
         yaxis = list(title = "average precipitation(mm)")
  )
```