Number of Storms by Basin

Row

Number of storms per basin by year

Storms Percentage per basin by year

Column

Number of storms per basin by year with wind greater than 75 percentile (3rd quantile)

Number of storms per basin by year with wind pressure greater than 75 percentile (3rd quantile)

Year Wise Storm Data

Column

Storm Data for 2012

Storm Data for 2013

Storm Data for 2014

Storm Data for 2015

Storm Data for 2016

Monthly Storm Data Analysis

Column

NA Basin

WP Basin

EP Basin

---
title: "Anly 512: Data Visualization"
author: "Nadeem Jamal"
date: "`r Sys.Date()`"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code : embed 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(flexdashboard)
library(knitr)
library(ggplot2)
library(ggthemes)
library(quantmod)
library(plyr)
library(DT)
library(quantmod)
library(plyr)
library(DT)
library(dygraphs)
library(xts)
library(zoo)
library(dplyr)
require(dplyr)
library(scales)
library(lubridate)
library(plotly)
library(rnoaa)
library(ggmap)
library(widgetframe)
library(rbokeh)
library(maps)

STRM_2012 = storm_data(year='2012')
STRM_2013 = storm_data(year='2013')
STRM_2014 = storm_data(year='2014')
STRM_2015 = storm_data(year='2015')
STRM_2016 = storm_data(year='2016')
structure(STRM_2016)
STRM_2012_SUBSET = select(STRM_2012,serial_num,iso_time,season,num,basin,sub_basin,name,nature,latitude,longitude,wind.wmo.,pres.wmo.,center,	wind.wmo..percentile	,pres.wmo..percentile,track_type,latitude_for_mapping,longitude_for_mapping,	current.basin)
STRM_2013_SUBSET = select(STRM_2013,serial_num,iso_time,season,num,basin,sub_basin,name,nature,latitude,longitude,wind.wmo.,pres.wmo.,center,	wind.wmo..percentile	,pres.wmo..percentile,track_type,latitude_for_mapping,longitude_for_mapping,	current.basin)
STRM_2014_SUBSET = select(STRM_2014,serial_num,iso_time,season,num,basin,sub_basin,name,nature,latitude,longitude,wind.wmo.,pres.wmo.,center,	wind.wmo..percentile	,pres.wmo..percentile,track_type,latitude_for_mapping,longitude_for_mapping,	current.basin)
STRM_2015_SUBSET = select(STRM_2015,serial_num,iso_time,season,num,basin,sub_basin,name,nature,latitude,longitude,wind.wmo.,pres.wmo.,center,	wind.wmo..percentile	,pres.wmo..percentile,track_type,latitude_for_mapping,longitude_for_mapping,	current.basin)
STRM_2016_SUBSET = select(STRM_2016,serial_num,iso_time,iso_time,season,num,basin,sub_basin,name,nature,latitude,longitude,wind.wmo.,pres.wmo.,center,	wind.wmo..percentile	,pres.wmo..percentile,track_type,latitude_for_mapping,longitude_for_mapping,	current.basin)
STORM_DATA_2012_2016=rbind(STRM_2012_SUBSET,STRM_2013_SUBSET,STRM_2014_SUBSET,STRM_2015_SUBSET,STRM_2016_SUBSET)

STORM_DATA_2012_2016$season = factor(STORM_DATA_2012_2016$season)
STORM_DATA_2012_2016$serial_num = factor(STORM_DATA_2012_2016$serial_num)
STORM_DATA_2012_2016$name = factor(STORM_DATA_2012_2016$name)


#To avoid downloading everytime, lets write this to a csv file
write.csv(STORM_DATA_2012_2016, file = 'STORM_DATA_2012_2016.csv')

STORM_DATA_2012_2016 <- read.csv(file = 'STORM_DATA_2012_2016.csv', header = TRUE)
STORM_DATA_2012_2016$season = factor(STORM_DATA_2012_2016$season)
STORM_DATA_2012_2016$serial_num = factor(STORM_DATA_2012_2016$serial_num)
STORM_DATA_2012_2016$name = factor(STORM_DATA_2012_2016$name)

STORM_DATA_2012_2016$iso_time = as.Date(STORM_DATA_2012_2016$iso_time, format = "%Y-%m-%d")
STORM_DATA_2012_2016$iso_months = months(STORM_DATA_2012_2016$iso_time)
STORM_DATA_2012_2016$iso_month = month(STORM_DATA_2012_2016$iso_time)
STORM_DATA_2012_2016$iso_month = factor(STORM_DATA_2012_2016$iso_month)

STORM_DATA_2012_2016 =STORM_DATA_2012_2016[STORM_DATA_2012_2016$wind.wmo.!="-999",]
STORM_DATA_2012_2016 =STORM_DATA_2012_2016[STORM_DATA_2012_2016$wind.wmo.!=-1,]
STORM_DATA_2012_2016 =STORM_DATA_2012_2016[STORM_DATA_2012_2016$wind.wmo.!=0,]
STORM_DATA_2012_2016 =STORM_DATA_2012_2016[STORM_DATA_2012_2016$pres.wmo.!=-1,]
STORM_DATA_2012_2016 =STORM_DATA_2012_2016[STORM_DATA_2012_2016$pres.wmo.!=0,]
STORM_DATA_2012_2016$Basin_name = as.factor(paste(STORM_DATA_2012_2016$name, STORM_DATA_2012_2016$basin, 
    sep = "."))

summary(STORM_DATA_2012_2016)
```

Number of Storms by Basin
============================================================================
Sidebar {.sidebar data-width=300}
-----------------------------------------------------------------------


### Storm Data   

This dashbord shows the occurrence of storms by number and area year over year. The data is from the NCDC website and is downloaded using rnoaa package. Data for the storms is from 2012 to 2016 across the world. The dashboard depicts the changes in storms occurrence over the given period across different regions.

The dashboard helps in analyzing the pattern of storms. Based on the visualization following questions emerges which can be addressed by further data analysis:

1)	Why the number of storms in SI basin has been decreasing consistently over the years?

2)	What might have caused a surge in storms in 2015 in WP basin?

3)	Why only in the month of February there are no storms in the WP basin?

4)	Why for EP basin, in the month of November the wind knots are less than 100?


Row
-----------------------------------------------------------------------

### Number of storms per basin by year

```{r echo=FALSE}

STORM_DATA_2012_2016 %>%
  group_by(basin, season) %>% tally() %>%ggplot( aes(x=basin, y=n, fill=season)) + geom_bar(stat="identity",position="dodge")+ ggtitle("Number of storms per basin by year")+labs(x="Basin Name",y="Number of storms")

```



### Storms Percentage per basin by year

```{r echo=FALSE}

STORM_DATA_2012_2016 %>%
  group_by(basin, season) %>% tally() %>%ggplot( aes(x=basin, y=n, fill=season)) + geom_bar(stat="identity",position="fill")+ ggtitle("Storms Percentage per basin by year")+labs(x="Basin Name",y="Percentage")

```





Column 
-----------------------------------------------------------------------
### Number of storms per basin by year with wind greater than 75 percentile (3rd quantile)

```{r echo=FALSE}

STORM_DATA_2012_2016[STORM_DATA_2012_2016$wind.wmo..percentile>=75,] %>%
  group_by(basin, season) %>% tally() %>%ggplot( aes(x=basin, y=n, fill=season)) + geom_bar(stat="identity",position="dodge")+ ggtitle("Number of storms per basin by year")+labs(x="Basin Name",y="Number of storms")

```

### Number of storms per basin by year with wind pressure greater than 75 percentile (3rd quantile)

```{r echo=FALSE}

STORM_DATA_2012_2016[STORM_DATA_2012_2016$pres.wmo.>=75,] %>%
  group_by(basin, season) %>% tally() %>%ggplot( aes(x=basin, y=n, fill=season)) + geom_bar(stat="identity",position="dodge")+ ggtitle("Number of storms per basin by year")+labs(x="Basin Name",y="Number of storms")

```


Year Wise Storm Data
===========================================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------








### Spatial Visualization of Storms and wind speed

Storm Data for each year from 2012 to 2016 with fill of wind speed.


Column {.tabset}
-----------------------------------------------------------------------
### Storm Data for 2012
```{r fig.height=3, fig.width=9, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}

 suppressWarnings(figure(width = 1200, height = 650, padding_factor = 0) %>%
  ly_map("world", col = "gray") %>%
  ly_points(longitude_for_mapping, latitude_for_mapping,color=wind.wmo..percentile, data = STORM_DATA_2012_2016[STORM_DATA_2012_2016$season=='2012',], size = 4,
            hover = c(basin)))

```

### Storm Data for 2013
```{r fig.height=3, fig.width=9, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}

 suppressWarnings(figure(width = 1200, height = 650, padding_factor = 0) %>%
  ly_map("world", col = "gray") %>%
  ly_points(longitude_for_mapping, latitude_for_mapping,color=wind.wmo..percentile, data = STORM_DATA_2012_2016[STORM_DATA_2012_2016$season=='2013',], size = 4,
            hover = c(basin)))

```


### Storm Data for 2014
```{r fig.height=3, fig.width=9, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}

 suppressWarnings(figure(width = 1200, height = 650, padding_factor = 0) %>%
  ly_map("world", col = "gray") %>%
  ly_points(longitude_for_mapping, latitude_for_mapping,color=wind.wmo..percentile, data = STORM_DATA_2012_2016[STORM_DATA_2012_2016$season=='2014',], size = 4,
            hover = c(basin)))

```


### Storm Data for 2015
```{r echo=FALSE, fig.height=3, fig.width=9, message=FALSE, warning=FALSE, Echo=FALSE, paged.print=FALSE}

 suppressWarnings(figure(width = 1200, height = 650, padding_factor = 0) %>%
  ly_map("world", col = "gray") %>%
  ly_points(longitude_for_mapping, latitude_for_mapping,color=wind.wmo..percentile, data = STORM_DATA_2012_2016[STORM_DATA_2012_2016$season=='2015',], size = 4,
            hover = c(basin)))

```

### Storm Data for 2016
```{r fig.height=3, fig.width=9, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}

 suppressWarnings(figure(width = 1200, height = 650, padding_factor = 0) %>%
  ly_map("world", col = "gray") %>%
  ly_points(longitude_for_mapping, latitude_for_mapping,color=wind.wmo..percentile, data = STORM_DATA_2012_2016[STORM_DATA_2012_2016$season=='2016',], size = 4,
            hover = c(basin)))

```



Monthly Storm Data Analysis
===========================================================================================
Sidebar {.sidebar}
-----------------------------------------------------------------------

### Seasonal Storm Analysis

Month wise paths of storms for three regions with highest number of storms i.e. NA Basin, 
WP Basin, and EP Basin


Column {.tabset}
-----------------------------------------------------------------------
### NA Basin
```{r echo=FALSE}
ggplot(STORM_DATA_2012_2016, aes(x = longitude_for_mapping, y = latitude_for_mapping, group = Basin_name)) + 
    geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group), 
        fill = "Green4", colour = "Gray10", size = 0.2) + geom_path(data = STORM_DATA_2012_2016, 
    aes(group = Basin_name, colour = wind.wmo.), size = 2) + xlim(-180, -20) + ylim(3, 
    80) +  labs(x = "", y = "", colour = "Wind \n(knots)") + scale_color_gradient2(midpoint=70, low="white", mid="blue",
                     high="dark orange", space ="Lab" )+facet_wrap(~iso_months)

```

### WP Basin
```{r echo=FALSE}
ggplot(STORM_DATA_2012_2016, aes(x = longitude_for_mapping, y = latitude_for_mapping, group = Basin_name)) + 
    geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group), 
        fill = "green4", colour = "gray10", size = 0.2) + geom_path(data = STORM_DATA_2012_2016, 
    aes(group = Basin_name, colour = wind.wmo.), size = 2) + xlim(80, 150) + ylim(0, 
    50) +  labs(x = "", y = "", colour = "Wind \n(knots)") +scale_color_gradient2(midpoint=70, low="white", mid="blue",
                     high="dark orange", space ="Lab" )+facet_wrap(~iso_months)

```

### EP Basin
```{r echo=FALSE}


ggplot(STORM_DATA_2012_2016, aes(x = longitude_for_mapping, y = latitude_for_mapping, group = Basin_name)) + 
    geom_polygon(data = map_data("world"), aes(x = long, y = lat, group = group), 
        fill = "green4", colour = "gray10", size = 0.2) + geom_path(data = STORM_DATA_2012_2016, 
    aes(group = Basin_name, colour = wind.wmo.), size = 2) + xlim(40, 150) + ylim(-40, 
    5) +  labs(x = "", y = "", colour = "Wind \n(knots)") +scale_color_gradient2(midpoint=70, low="white", mid="blue",
                     high="dark orange", space ="Lab" )+facet_wrap(~iso_months)


```