chooseCRANmirror(graphics=FALSE, ind=1)
knitr::opts_chunk$set(echo = TRUE)
install.packages("ggplot2")
##
## The downloaded binary packages are in
## /var/folders/c6/jk_qvd1d6lbcj4tzd8gg2rrh0000gn/T//Rtmp9onVxZ/downloaded_packages
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.2
install.packages("tsModel")
##
## The downloaded binary packages are in
## /var/folders/c6/jk_qvd1d6lbcj4tzd8gg2rrh0000gn/T//Rtmp9onVxZ/downloaded_packages
install.packages("csvread")
##
## The downloaded binary packages are in
## /var/folders/c6/jk_qvd1d6lbcj4tzd8gg2rrh0000gn/T//Rtmp9onVxZ/downloaded_packages
install.packages("dplyr")
##
## The downloaded binary packages are in
## /var/folders/c6/jk_qvd1d6lbcj4tzd8gg2rrh0000gn/T//Rtmp9onVxZ/downloaded_packages
install.packages("sqldf")
##
## The downloaded binary packages are in
## /var/folders/c6/jk_qvd1d6lbcj4tzd8gg2rrh0000gn/T//Rtmp9onVxZ/downloaded_packages
require(sqldf)
## Loading required package: sqldf
## Warning: package 'sqldf' was built under R version 3.3.2
## Loading required package: gsubfn
## Loading required package: proto
## Warning in doTryCatch(return(expr), name, parentenv, handler): unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
## dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
## Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so
## Reason: image not found
## Could not load tcltk. Will use slower R code instead.
## Loading required package: RSQLite
## Warning: package 'RSQLite' was built under R version 3.3.2
library(ggplot2)
setwd("/Users/dikshagupta/Desktop/")
ny1 <- read.csv("ccrb.csv", header=T)
#Histogram of
hist(ny1$Received.Year, breaks=10, col="blue")

#Incidence of Occurance
p1_ny<-unique(data.frame(ny1$UniqueComplaintId,ny1$Borough.of.Occurrence,ny1$Encounter.Outcome))
Plot1<-ggplot(p1_ny,aes(ny1.Borough.of.Occurrence))+geom_bar(aes(fill = ny1.Encounter.Outcome))+ scale_fill_discrete(name = "Outcome")+ggtitle("Incidence by Occurrence")+theme(legend.position = "right")+xlab("Occurance")+theme(plot.title = element_text(hjust = 0.7))
Plot1

#Recieved Year
t2<-aggregate(ny1$UniqueComplaintId, by=list(ny1$Received.Year), FUN=sum)
t2
## Group.1 x
## 1 1999 539981
## 2 2000 79830
## 3 2002 893779
## 4 2003 996779
## 5 2004 29814832
## 6 2005 413272899
## 7 2006 823054274
## 8 2007 855706807
## 9 2008 784929066
## 10 2009 736596973
## 11 2010 605387377
## 12 2011 570530016
## 13 2012 543122553
## 14 2013 519733279
## 15 2014 477093617
## 16 2015 446907873
## 17 2016 299782127
Year<-t2$Group.1
complains <-t2$x
plot(Year, complains)

## Warning: Ignoring unknown parameters: binwidth, bins, pad

#Completed VS Incomplete Investigation
p3_ny<-unique(data.frame(ny1$UniqueComplaintId,ny1$Encounter.Outcome,ny1$Is.Full.Investigation))
Plot3<-ggplot(p3_ny,aes(ny1.Encounter.Outcome))+geom_bar(aes(fill=ny1.Is.Full.Investigation))+ggtitle("Completed VS Incomplete Investigation")+theme(legend.position="right")+scale_fill_discrete(name = "Investigation Closed:True/False")+ xlab("End results")+theme(plot.title=element_text(hjust=0.8))
Plot3

#Pie chart for Completed VS Incomplete Investigation
pie1<-table(ny1$Is.Full.Investigation)
pie(pie1)

#Incident Year Vs Received Year
ggplot(ny1,aes(ny1$Incident.Year,ny1$Received.Year))+geom_point() + geom_smooth(method = lm) + labs (title = "Incident Year Vs Received Year", x="Incident Year", y="Received Year")+scale_x_continuous(breaks = seq(1999,2016,1))+scale_y_continuous(breaks = seq(1999,2016,1))+theme(panel.grid.minor = element_line(colour="blue", size=0.5))

#Closed Year Vs Received Year
ggplot(ny1,aes(ny1$Close.Year,ny1$Received.Year))+geom_point() + geom_smooth(method = lm) + labs (title = "Closed Year Vs Received Year", x="Closed Year", y="Received Year")+scale_x_continuous(breaks = seq(1999,2016,1))+scale_y_continuous(breaks = seq(1999,2016,1))+theme(panel.grid.minor = element_line(colour="green", size=0.5))

#Pie chart to show Closed Year Vs Received Year
pie2<-table(ny1$Complaint.Has.Video.Evidence)
pie(pie2)

#Most Cases dont seem to have a video evidence according to the pie chart. Breaking down the cases that have video evidences seem to be increasing after the year 2010
#Number of Incident Occurred has Evidence
ggplot(ny1, aes(x=ny1$Incident.Year, fill = ny1$Complaint.Has.Video.Evidence))+geom_histogram(stat="count")+ labs (title = "Number of Incident Occurred has Evidence", x="Year", y="Number Of Incidents") + theme (legend.position = "right") + scale_fill_discrete(name = "Is Video Evidence")+scale_x_continuous(breaks = seq(1999,2016,2))
## Warning: Ignoring unknown parameters: binwidth, bins, pad

#Complaint filed mode
barplot(table(ny1$Complaint.Filed.Mode), xlab = "Mode", ylab = "Count", main = "Mode of filing the complain", col = c(1,2,3,4,5,6,7))

#Incident Location
barplot(table(ny1$Incident.Location), xlab = "Location", ylab = "Count", col = c(1:15))

#The analysis of this paper shows thats most of the cases do not have video evidence. The number of video evidences increases after 2011. The number of cases that are solved after 2010 also increase, stating that the closing the complaints can be directly related to the precence of an evidence. Most of the incidences seem to be around the school and apartment locations. The most number of complains seem to be from brooklyn and around abuse of authority.