1960-2014 UCR violent crimes data

Data obtained from https://www.ucrdatatool.gov

require(ggplot2)
require(dplyr)
#library(plyr)
library(knitr)
library(DT)
library(xtable)
require(ggplot2)
require(reshape)
allc<-read.csv("C:/Users/vivek/Downloads/CrimeStatebyState.csv",header= TRUE)

Sneak peak into the data

##   Year Population Violent.crime.total Murder.and.nonnegligent.Manslaughter
## 1 1960  179323175              288460                                 9110
## 2 1961  182992000              289390                                 8740
## 3 1962  185771000              301510                                 8530
## 4 1963  188483000              316970                                 8640
## 5 1964  191141000              364220                                 9360
## 6 1965  193526000              387390                                 9960
##   Legacy.rape..1 Revised.rape..2 Robbery Aggravated.assault  X X.1 X.2 X.3
## 1          17190              NA  107840             154320 NA  NA  NA  NA
## 2          17220              NA  106670             156760 NA  NA  NA  NA
## 3          17550              NA  110860             164570 NA  NA  NA  NA
## 4          17650              NA  116470             174210 NA  NA  NA  NA
## 5          21420              NA  130390             203050 NA  NA  NA  NA
## 6          23410              NA  138690             215330 NA  NA  NA  NA
##    Year Population Violent.crime.total
## 53 2012  313873685             1217067
## 54 2013  316497531             1199684
## 55 2014  318857056             1197987
## 56 2015  321418820             1197704
## 57   NA         NA                  NA
## 58   NA         NA                  NA
##    Murder.and.nonnegligent.Manslaughter Legacy.rape..1 Revised.rape..2
## 53                                14866          85141              NA
## 54                                14319          82109          113695
## 55                                14249          84041          116645
## 56                                15696             NA              NA
## 57                                   NA             NA              NA
## 58                                   NA             NA              NA
##    Robbery Aggravated.assault  X X.1 X.2 X.3
## 53  355051             762009 NA  NA  NA  NA
## 54  345095             726575 NA  NA  NA  NA
## 55  325802             741291 NA  NA  NA  NA
## 56      NA                 NA NA  NA  NA  NA
## 57      NA                 NA NA  NA  NA  NA
## 58      NA                 NA NA  NA  NA  NA

Creating a copy of the data

#taking out any na values
df<-na.omit(df)

dfcopy<-df

head(dfcopy)
##   Year population total_violent murder_manslaughter
## 1 1960  179323175        288460                9110
## 2 1961  182992000        289390                8740
## 3 1962  185771000        301510                8530
## 4 1963  188483000        316970                8640
## 5 1964  191141000        364220                9360
## 6 1965  193526000        387390                9960
tail(dfcopy)
##    Year population total_violent murder_manslaughter
## 51 2010  309330219       1251248               14722
## 52 2011  311587816       1206031               14661
## 53 2012  313873685       1217067               14866
## 54 2013  316497531       1199684               14319
## 55 2014  318857056       1197987               14249
## 56 2015  321418820       1197704               15696

Please note that data for year 2015 obtained from ‘https://ucr.fbi.gov/crime-in-the-u.s/2015/crime-in-the-u.s.-2015/tables/table-1’ and was appended to the ucr dataset which has data from 1960-2014

Scaling ‘population’ column for better visualization

df$population<-df$population/1000000

Simple plots for first glance

plot(df$Year,df$population, xlab = 'Year', ylab = 'Population (in millions)',main = "1960-2015 US Population" )

plot(df$Year,df$total_violent, xlab = 'Year', ylab = 'Violent crime', main = "1960-2015 All Violent Crimes")

Plotting with qplot

qplot(df$Year,df$population, xlab = 'Year', ylab = 'Population (in millions)',main = "1960-2015 US Population" ,geom = c("point", "smooth"))
## `geom_smooth()` using method = 'loess'

qplot(df$Year,df$total_violent, xlab = 'Year', ylab = 'Violent crime', main = "1960-2015 All Violent Crimes",geom = c("point", "smooth"))
## `geom_smooth()` using method = 'loess'

As can be seen from graph below, crime rates have been reducing significantly over the years.

qplot(df$Year,df$murder_manslaughter, xlab = 'Year', ylab = 'Murder & Non negligent Manslaughter',main = "1960-2015 US Murder & Manslaughter" ,geom = c("point", "smooth"))
## `geom_smooth()` using method = 'loess'

Attempting to plot Population, Total Violent Crimes , Murder & manslaughter(involuntary) in one plot using ggplot2

df$total_violent<-df$total_violent
df$murder_manslaughter<-df$murder_manslaughter


df2 <- melt(data = df, id.vars = "Year")
ggplot(data = df2, aes(x = Year, y = value, colour = variable)) + geom_line()+ggtitle("1960-2015 US Population Violent Crime and Murders") +
  labs(x="Year",y=" Numbers (in millions)")  

Above plot isn’t very readable, so let’s scale the columns in the dataframe

df$total_violent<-df$total_violent/10000
df$murder_manslaughter<-df$murder_manslaughter/100
#making sure all values are in same range
df[1:4,]
##   Year population total_violent murder_manslaughter
## 1 1960   179.3232        28.846                91.1
## 2 1961   182.9920        28.939                87.4
## 3 1962   185.7710        30.151                85.3
## 4 1963   188.4830        31.697                86.4
df2 <- melt(data = df, id.vars = "Year")

Plotting scaled values

Please take note of the following measurement units for the above graph:

  1. Population is being measured in the millions (1 unit on graph = 1 million)
  2. Total Violent crime is being measured in the 10,000’s (1 unit on graph = 10000)
  3. Murder and Manslaughter(non-negligent) is being measured in the 100’s (1 unit on graph = 100)

Clearly crime rates have been reducing over the years.

dfcopy <- dfcopy[order(-(dfcopy$murder_manslaughter)),]
aa<-1:nrow(dfcopy)
rownames(dfcopy)<-aa
dfcopy$Rank<-rownames(dfcopy)

Ranking the years in descending order of murders and involuntary manslaughter

kable(dfcopy)
Year population total_violent murder_manslaughter Rank
1991 252153092 1911767 24703 1
1993 257782608 1926017 24526 2
1992 255029699 1932274 23760 3
1990 249464396 1820127 23438 4
1994 260327021 1857670 23326 5
1980 225349264 1344520 23040 6
1981 229465714 1361820 22520 7
1995 262803276 1798792 21606 8
1989 246819230 1646037 21500 9
1979 220099000 1208030 21460 10
1982 231664458 1322390 21010 11
1974 211392000 974720 20710 12
1988 244498982 1566221 20675 13
1986 240132887 1489169 20613 14
1975 213124000 1039710 20510 15
1987 242288918 1483999 20096 16
1996 265228572 1688540 19645 17
1973 209851000 875910 19640 18
1978 218059000 1085550 19560 19
1983 233791994 1258087 19308 20
1977 216332000 1029580 19120 21
1985 237923795 1327767 18976 22
1976 214659000 1004210 18780 23
1984 235824902 1273282 18692 24
1972 208230000 834900 18670 25
1997 267783607 1636096 18208 26
1971 206212000 816500 17780 27
2006 299398484 1435123 17309 28
2007 301621157 1422970 17128 29
1998 270248003 1533887 16974 30
2005 296507061 1390745 16740 31
2003 290788976 1383676 16528 32
2008 304059724 1394461 16465 33
2002 287973924 1423677 16229 34
2004 293656842 1360088 16148 35
2001 285317559 1439480 16037 36
1970 203235298 738820 16000 37
2015 321418820 1197704 15696 38
2000 281421906 1425486 15586 39
1999 272690813 1426044 15522 40
2009 307006550 1325896 15399 41
2012 313873685 1217067 14866 42
1969 201385000 661870 14760 43
2010 309330219 1251248 14722 44
2011 311587816 1206031 14661 45
2013 316497531 1199684 14319 46
2014 318857056 1197987 14249 47
1968 199399000 595010 13800 48
1967 197457000 499930 12240 49
1966 195576000 430180 11040 50
1965 193526000 387390 9960 51
1964 191141000 364220 9360 52
1960 179323175 288460 9110 53
1961 182992000 289390 8740 54
1963 188483000 316970 8640 55
1962 185771000 301510 8530 56

In terms of murder and manslaughter , 2014 and 2015 are no where near the bloodiest of years, in fact they are ranked #38 and #47 respectively in the 55 years between 1960-2015 But 2015 definitely saw a small rise in the murder rate.

The availability of 2016 2017 data could help us decide whether or not the violent crime rate has risen .

https://www.linkedin.com/in/vivekmangipudi/