oncDF <- read.csv("~/Desktop/MATH239/OneNightCount.csv",
                  header=TRUE)
library(tidyverse)
## ── Attaching packages ─────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 2.2.1     ✔ purrr   0.2.5
## ✔ tibble  1.4.2     ✔ dplyr   0.7.5
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ readr   1.1.1     ✔ forcats 0.3.0
## ── Conflicts ────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
# GATHER DATA TO TIDY
oncG<-oncDF%>%
  gather(City, Count, -c(Location,YEAR))

#View(oncG)

# TOTAL COUNTS 
oncTot<-oncG%>%
  filter(Location=="TOTAL", 
         !City %in% c("TOTAL", "EAST.SIDE", 
                      "NIGHT.OWL.BUSES", "NORTH.END"))

# STACKED BAR CHART (SHOWS OVERALL TOTAL FOR KING COUNTY)
ggplot(oncTot, aes(YEAR, Count, fill=City))+
  geom_bar(stat="identity")
## Warning: Removed 19 rows containing missing values (position_stack).

# GATHER DATA TO TIDY
oncG<-oncDF%>%
  gather(City, Count, -c(Location,YEAR))

#View(oncG)

# TOTAL COUNTS 
oncTot<-oncG%>%
  filter(Location=="TOTAL", 
         !City %in% c("TOTAL", "EAST.SIDE", 
                      "NIGHT.OWL.BUSES", "NORTH.END"))

# STACKED BAR CHART (SHOWS OVERALL TOTAL FOR KING COUNTY)
ggplot(oncTot, aes(YEAR, Count, fill=City))+
  geom_bar(stat="identity")
## Warning: Removed 19 rows containing missing values (position_stack).

# SIDE-BY-SIDE BAR CHART
ggplot(oncTot, aes(YEAR, Count, fill=City))+
  geom_bar(stat="identity", position="dodge")
## Warning: Removed 19 rows containing missing values (geom_bar).

# LOOK AT THE LOCATIONS OF HOMELESS
oncLoc<-oncG%>%
  filter(Location!="TOTAL", 
         !City %in% c("TOTAL", "EAST.SIDE", 
                      "NIGHT.OWL.BUSES", "NORTH.END"))

# SIDE-BY-SIDE BAR CHART
# WITH FACET FOR LOCATION
ggplot(oncLoc, aes(YEAR, Count, fill=Location))+
  geom_bar(stat="identity", position="dodge")+
  facet_wrap(~City, scales="free")+
  theme_bw()
## Warning: Removed 228 rows containing missing values (geom_bar).

# SEATTLE ONLY
oncSEA<-oncG%>%
  filter(Location!="TOTAL", 
         City == "SEATTLE")

# SIDE-BY-SIDE BAR CHART
# WITH FACET FOR LOCATION
ggplot(oncSEA, aes(YEAR, Count, fill=Location))+
  geom_bar(stat="identity", position="dodge")+
  theme_bw()