---
title: "Gun Violence in United States of America from January - October 2019"
author: "Mutum Deva Neil Singh (s3773370)"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
# Required packages.
library(ggplot2)
library(plotly)
library(plyr)
library(flexdashboard)
library(readr)
library(magrittr)
library(dplyr)
library(tidyr)
# Data import.
Gun_Violence <- read_csv("Gun Violence.csv")
# Making the data suitable to plot.
## Renaming # Killed and # Injured to Killed and Injured respectively.
colnames(Gun_Violence)[colnames(Gun_Violence)=="# Killed"] <- "Killed"
colnames(Gun_Violence)[colnames(Gun_Violence)=="# Injured"] <- "Injured"
## Dropping Operations column because it only has NAs.
Gun_Violence$Operations <- NULL
## Creating a new column Total casualties.
Gun_Violence$`Total Casualties` <- Gun_Violence$Killed + Gun_Violence$Injured
## Seperating the date, month and year.
Gun_Violence <- Gun_Violence %>% separate(`Incident Date`, into = c("Date", "Year"), sep = ",")
Gun_Violence <- Gun_Violence %>% separate(Date, into = c("Month", "Date"), sep = " ")
Gun_Violence$Month <- factor(Gun_Violence$Month, levels = c("January","February","March","April","May","June","July",
"August","September","October"), ordered = TRUE)
## Plot 1.
plot1 <-ggplot(data = Gun_Violence, aes(x = Month, `Total Casualties`))
plot1 <- plot1 + geom_line()
## Plot 2.
plot2 <- ggplot(data = Gun_Violence, aes(x = State, y = Killed))
plot2 <- plot2 + geom_jitter(width = .2, alpha = .25) +
stat_summary(fun.y = "mean", geom = "point", colour = "red") + theme(axis.text.x=element_text(angle=90,hjust=1))
## Plot 3.
plot3 <- ggplot(Gun_Violence, aes(x = State, y = Injured))
plot3 <- plot3 + geom_violin() +
stat_summary(fun.y = "mean", geom = "point", colour = "red") + theme(axis.text.x=element_text(angle=90,hjust=1))
## Plot 4.
plot4 <- ggplot(data = Gun_Violence, aes(x = State, y = `Total Casualties`))
plot4 <- plot4 + geom_boxplot() + theme(axis.text.x=element_text(angle=90,hjust=1))
```
Row
-----------------------------------------------------------------------
### Total casualties month-wise
```{r}
ggplotly(plot1)
```
### Deaths state-wise
```{r}
ggplotly(plot2)
```
Row
-----------------------------------------------------------------------
### Injuries state-wise
```{r}
ggplotly(plot3)
```
### Total casualties state-wise
```{r}
ggplotly(plot4)
```