pckgs <- c("tidyverse","RColorBrewer","ggplot2","hrbrthemes")
lapply(pckgs, library, character.only=TRUE)

#setting up directories
output_dir = "~/Dropbox/chyn_campos_bruhn/Gangs/data/crime"

Data Cleaning

First, I merged the LAUSD student data and the LA Sheriff Crime data so that only overlapping census blocks in the two dataset remain. This gives me a merged dataset that will later be used for summary statistics and visualization.

Note: since it takes a long time to load the LAUSD student data, here I only loaded the merged dataset in this R markdown. The code to merge the dataset is still included as comments.

The below table tabulates the number of census blocks with and without gang presence in the merged dataset.

### load LA Sheriff crime data 
#sheriff_crime <- read_csv(str_interp("${output_dir}/Sheriff/output/panel_data_crimela_0521.csv"))


### get all the censusblock in the student lausd data and the gang present indicator
#student_blockid <- unique(student_data[c("censusblockid","gang_present")]) %>% drop_na("censusblockid") %>% rename(census_block = censusblockid)

### merge in with crime data
#sheriff_crime_lausd <- sheriff_crime %>% inner_join(student_blockid, by = "census_block") %>% drop_na(gang_present)
#write.csv(sheriff_crime_lausd, file = str_interp("${output_dir}/Sheriff/output/merged_student_sheriff.csv"))

sheriff_crime_lausd <- read_csv(str_interp("${output_dir}/Sheriff/output/merged_student_sheriff.csv"))
knitr::kable(table(unique(sheriff_crime_lausd[c("census_block","gang_present")])$gang_present), col.names = c("Presence of Gangs","Number of Census Blocks") )
Presence of Gangs Number of Census Blocks
0 5364
1 4270

After merging the data, I collapsed it on the year and gang+_present variable to calculate some summary statistics of different crime types. Specifically, I calculated the sum, mean, and standard deviation. Note that the mean here is calculated as:

\[ Mean_{ijt} = \frac{\sum Crime_{ijt}}{\sum_{j \in \{J_0,J_1\}} Block_j} \] where the subscript \(i\) denotes crime types, \(j\) denotes gang presence, and \(t\) denotes month-year. \(J_0\) is the set of census blocks without gang presence, and \(J_1\) is the set of census blocks with gang presence. In words, the average for each crime type here is the count of all that crime types within all the census blocks with/without gang presence, divided by the number of census blocks with/without gang presence.

Year Presence of Gangs Count of Robbery Average:Robbery SD:Robbery Count of Homicide Average:Homicide SD:Homicide Count of Burglary Average:Burglary SD:Burglary Count of Weapon cases Average:Weapon cases SD:Weapon cases Count of Assault Average:Assualt SD:Assault Count of Sexual cases Average:Sexual cases SD:sexual cases Count of Theft Average:Theft SD:Theft Count of Fraud Average:Fraud SD:Fraud Count of Vandalism Average:Vandalism SD:Vandalism Count of Alcohol Average:Alcohol SD:Alcohol
2005 0 939 8.928402 0.3221213 79 0.7511648 0.0885229 1471 13.986878 0.4129481 656 6.237520 0.2600366 1466 13.939336 0.4243503 382 3.6322145 0.3043561 2729 25.94846 0.7066269 661 6.285062 0.2545620 1585 15.070838 0.6534375 417 3.9650090 0.2292068
2006 0 908 8.610716 0.3185309 56 0.5310574 0.0726834 1290 12.233286 0.3766958 651 6.173542 0.2533557 1428 13.541963 0.4081655 369 3.4992888 0.3104294 2560 24.27691 0.7063359 718 6.808914 0.2644016 1732 16.424846 0.7271769 473 4.4855382 0.2451702
2007 0 1017 8.928101 0.3199815 53 0.4652796 0.0680555 1463 12.843473 0.3737549 660 5.794048 0.2485709 1488 13.062944 0.4629963 376 3.3008515 0.1854186 2974 26.10833 0.7552880 847 7.435695 0.2735035 1724 15.134756 0.5858349 576 5.0566237 0.2536604
2008 0 965 8.173118 0.3074722 48 0.4065385 0.0636333 1556 13.178623 0.3997861 719 6.089608 0.2549220 1480 12.534937 0.4499782 423 3.5826205 0.2078107 2953 25.01059 0.6987585 893 7.563310 0.2769384 1746 14.787838 0.6287890 729 6.1743034 0.2785440
2009 0 907 8.274038 0.3086140 34 0.3101624 0.0556083 1526 13.920817 0.4038371 615 5.610290 0.3303929 1318 12.023353 0.4357792 353 3.2202153 0.2515589 2953 26.93851 0.8438698 756 6.896552 0.2643323 1588 14.486408 0.5574352 559 5.0994344 0.2699049
2010 0 983 8.691424 0.3218628 46 0.4067197 0.0650220 1636 14.465075 0.4006529 599 5.296198 0.2507881 1462 12.926614 0.4357177 384 3.3952255 0.3013458 3067 27.11760 0.9105984 758 6.702034 0.2674949 1520 13.439434 0.3926688 636 5.6233422 0.2837036
2011 0 877 7.838756 0.2957120 31 0.2770826 0.0525680 1561 13.952449 0.3961018 578 5.166250 0.2327712 1304 11.655345 0.4108146 332 2.9674651 0.2776094 3375 30.16625 0.9642251 716 6.399714 0.2589556 1380 12.334644 0.3884198 567 5.0679299 0.2720995
2012 0 913 8.056119 0.2957887 25 0.2205947 0.0469178 1640 14.471014 0.4034658 531 4.685432 0.2191261 1508 13.306274 0.4535756 366 3.2295068 0.2849595 3645 32.16271 0.9474672 849 7.491397 0.2826614 1358 11.982705 0.3595889 714 6.3001853 0.3036745
2013 0 772 7.138894 0.2880023 39 0.3606436 0.0599480 1550 14.333272 0.3877618 514 4.753098 0.2225536 1451 13.417792 0.4731101 301 2.7834289 0.1689430 3226 29.83170 0.7267866 760 7.027927 0.2703970 1298 12.002959 0.3861327 641 5.9275014 0.3087857
2014 0 730 7.079818 0.2793086 26 0.2521579 0.0501544 1366 13.247988 0.3805444 447 4.335176 0.2102195 1593 15.449520 0.4347747 281 2.7252449 0.1781852 3208 31.11240 0.9119273 697 6.759771 0.2657063 1309 12.695180 0.3863355 602 5.8384250 0.3152836
2015 0 703 6.605281 0.2715206 29 0.2724796 0.0521309 1303 12.242789 0.3705820 522 4.904632 0.2253436 1702 15.991732 0.4581551 265 2.4898995 0.2129084 3386 31.81434 0.8881630 756 7.103260 0.2693898 1442 13.548811 0.4046602 401 3.7677347 0.2273143
2016 0 827 7.436382 0.2891163 39 0.3506879 0.0591176 1197 10.763421 0.3385010 582 5.233342 0.2318098 1816 16.329467 0.4549347 255 2.2929593 0.1584414 3747 33.69301 0.7710198 745 6.699038 0.2626464 1797 16.158619 0.4591819 598 5.3772143 0.3387244
2017 0 907 8.372565 0.3126843 29 0.2677005 0.0516729 1275 11.769593 0.3621873 633 5.843257 0.2475903 1632 15.065079 0.4715051 281 2.5939260 0.1657842 3466 31.99483 0.8070418 659 6.083264 0.2455120 1669 15.406628 0.4358670 537 4.9570756 0.2850893
2018 0 741 7.362146 0.2920595 26 0.2583209 0.0507621 1082 10.750124 0.3506869 597 5.931446 0.2489224 1538 15.280676 0.5060233 219 2.1758569 0.1492678 3549 35.26080 1.0069114 643 6.388475 0.2545145 1424 14.148038 0.4034987 394 3.9145554 0.2321909
2019 0 738 7.270220 0.2928282 29 0.2856861 0.0533758 879 8.659245 0.3057552 590 5.812235 0.2446890 1518 14.954192 0.4711369 242 2.3840016 0.1765099 3355 33.05093 0.8691846 613 6.038814 0.2483407 1451 14.294158 0.4323828 472 4.6497882 0.2522906
2020 0 640 6.408331 0.2679537 40 0.4005207 0.0631630 914 9.151898 0.3346520 655 6.558526 0.2670281 1379 13.807950 0.4184543 151 1.5119656 0.1252744 2851 28.54711 0.6447435 474 4.746170 0.2209495 1504 15.059577 0.4329120 362 3.6247121 0.2649266
2021 0 552 6.006529 0.2522818 64 0.6964091 0.0844630 852 9.270947 0.3293942 599 6.517954 0.2630752 1263 13.743199 0.4267453 115 1.2513602 0.1140671 2895 31.50163 0.7112904 583 6.343852 0.2576536 1389 15.114255 0.4089891 221 2.4047878 0.1738371
2005 1 205 7.539537 0.2829103 19 0.6987863 0.0876209 283 10.408238 0.3616782 190 6.987863 0.2676603 346 12.725267 0.3787836 61 2.2434719 0.1505832 449 16.51342 0.6229764 100 3.677823 0.1940261 521 19.161456 0.8970495 51 1.8756896 0.1435944
2006 1 247 9.104313 0.3204626 11 0.4054552 0.0635579 244 8.993734 0.3370307 164 6.044969 0.2474697 363 13.380022 0.3675792 78 2.8750461 0.1714908 456 16.80796 0.6226299 98 3.612237 0.1885944 567 20.899373 0.9941756 39 1.4375230 0.1190538
2007 1 274 9.087894 0.3284251 10 0.3316750 0.0575052 259 8.590381 0.3127202 187 6.202322 0.2546200 342 11.343284 0.3384290 76 2.5207297 0.1609571 485 16.08624 0.5388004 101 3.349917 0.1818001 593 19.668325 1.2501316 66 2.1890547 0.1486002
2008 1 215 6.729265 0.2732788 14 0.4381847 0.0660607 269 8.419405 0.3486946 212 6.635368 0.2588043 337 10.547731 0.3545280 60 1.8779343 0.1380530 513 16.05634 0.6146385 153 4.788732 0.2150223 434 13.583725 0.9510642 75 2.3474178 0.1575082
2009 1 191 6.543337 0.2647320 7 0.2398082 0.0489198 277 9.489551 0.3335860 170 5.823912 0.2456610 267 9.146968 0.3272927 66 2.2610483 0.1509709 431 14.76533 0.5727899 112 3.836930 0.1956542 443 15.176430 0.8935395 59 2.0212402 0.1632932
2010 1 211 7.090054 0.2719614 14 0.4704301 0.0731848 305 10.248656 0.3428705 174 5.846774 0.2417211 316 10.618280 0.3432158 81 2.7217742 0.1647972 476 15.99462 0.6041497 114 3.830645 0.1954379 343 11.525538 0.4665148 82 2.7553763 0.2213333
2011 1 208 6.991597 0.2679077 11 0.3697479 0.0607046 295 9.915966 0.3429313 181 6.084034 0.2500759 315 10.588235 0.3288663 62 2.0840336 0.1497677 576 19.36134 0.6920819 82 2.756302 0.1637447 292 9.815126 0.3287092 114 3.8319328 0.2692686
2012 1 211 7.270848 0.2713852 9 0.3101309 0.0556126 283 9.751895 0.3338855 141 4.858718 0.2213596 389 13.404549 0.3717239 74 2.5499655 0.1598356 616 21.22674 0.7791764 125 4.307374 0.2446362 261 8.993797 0.3025379 155 5.3411440 0.3272741
2013 1 216 7.929515 0.2936919 10 0.3671072 0.0604892 284 10.425844 0.3514780 142 5.212922 0.2256078 402 14.757709 0.3986177 74 2.7165932 0.1692368 755 27.71659 1.1599479 108 3.964758 0.1988934 301 11.049927 0.3664901 143 5.2496329 0.3613198
2014 1 223 8.103198 0.3184214 12 0.4360465 0.0659017 293 10.646802 0.3535173 128 4.651163 0.2240100 461 16.751454 0.4279306 62 2.2529070 0.1484234 639 23.21948 0.7613500 115 4.178779 0.2019483 381 13.844477 0.4221479 165 5.9956395 0.3297373
2015 1 245 9.213990 0.3316884 11 0.4136894 0.0641976 213 8.010530 0.3004496 151 5.678827 0.2441374 478 17.976683 0.4320108 82 3.0838661 0.1793216 699 26.28808 0.9308779 107 4.024069 0.2022208 359 13.501316 0.4831745 124 4.6634073 0.2703128
2016 1 256 9.225225 0.3110460 9 0.3243243 0.0568673 217 7.819820 0.3002228 132 4.756757 0.2128878 459 16.540540 0.4250107 66 2.3783784 0.1524024 705 25.40541 0.7445771 108 3.891892 0.2025404 380 13.693694 0.4211273 106 3.8198198 0.2879151
2017 1 196 8.301567 0.2923668 8 0.3388395 0.0581235 198 8.386277 0.3090411 150 6.353240 0.2607601 332 14.061838 0.4113407 51 2.1601017 0.1511234 582 24.65057 0.7114481 96 4.066074 0.1996783 344 14.570097 0.4177618 71 3.0072003 0.2408186
2018 1 139 7.217030 0.2781837 6 0.3115265 0.0557420 164 8.515057 0.3024019 147 7.632399 0.2881021 267 13.862928 0.4569725 27 1.4018692 0.1219357 515 26.73936 0.7248080 91 4.724818 0.2170647 274 14.226376 0.4245821 46 2.3883697 0.1778681
2019 1 152 7.089552 0.2810087 9 0.4197761 0.0646691 149 6.949627 0.2951190 160 7.462687 0.2646190 255 11.893657 0.3758153 27 1.2593284 0.1156450 472 22.01493 0.6637362 79 3.684702 0.2050336 274 12.779851 0.4597587 69 3.2182836 0.2035378
2020 1 105 5.089675 0.2468579 12 0.5816772 0.0760641 164 7.949588 0.3168120 211 10.227824 0.3202049 210 10.179350 0.3344316 17 0.8240427 0.0956369 341 16.52933 0.4123664 67 3.247698 0.1826946 238 11.536597 0.3635575 70 3.3931168 0.3000362
2021 1 92 5.200678 0.2296163 19 1.0740531 0.1084546 124 7.009610 0.2963848 176 9.949124 0.3212757 244 13.793103 0.3777949 18 1.0175240 0.1110849 298 16.84568 0.4305893 58 3.278688 0.1812762 223 12.605992 0.3691195 16 0.9044658 0.0946991

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

#define custom color scale
myColors <- brewer.pal(4, "Spectral")
names(myColors) <- levels(sheriff_crime_lausd_grouped$`Presence of Gangs`)
custom_colors <- scale_colour_manual(name = "Presence of Gangs", values = myColors)

#visualization
sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_robbery, color = `Presence of Gangs`)) +
  geom_line() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,10,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Robbery (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_homicide, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(0,1,0.1))  +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Homicide (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_burglary, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,15,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Burglary (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_weapons, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,10,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Weapon Crimes (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_assault, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,18,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Assault (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_rape_sexual, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(1,5,0.5))  + 
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Sexual Crimes (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_theft, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,38,2)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Theft (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_fraud, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(1,10,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Fraud (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_vandalism, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(4,20,2)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Vandalism (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

sheriff_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_alcohol, color = `Presence of Gangs`)) +
  geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) + scale_y_continuous(breaks=seq(1,7,1)) +
  custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Alcohol Offenses (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

The below section repeats the above data cleaning, description, and visualization, but with the LAPD crime data.

### load and merge data from LAPD
#lapd_crime <- read_csv(str_interp("${output_dir}/LAPD/output/panel_data_crimela_1019.csv"))
#lapd_crime_lausd <- lapd_crime %>% inner_join(student_blockid, by = "census_block") %>% drop_na(gang_present)
#write.csv(lapd_crime_lausd , file = str_interp("${output_dir}/LAPD/output/merged_student_lapd.csv"))

lapd_crime_lausd <- read_csv(str_interp("${output_dir}/LAPD/output/merged_student_lapd.csv"))
knitr::kable(table(unique(lapd_crime_lausd[c("census_block","gang_present")])$gang_present), col.names = c("Presence of Gangs","Number of Census Blocks") )
Presence of Gangs Number of Census Blocks
0 9465
1 8815
lapd_crime_lausd_grouped <- lapd_crime_lausd  %>% 
  group_by(year, gang_present) %>% summarise(count_robbery = sum(robbery), mean_robbery = 100*mean(robbery), sd_robbery = sd(robbery),
                                             count_homicide = sum(homicide), mean_homicide = 100*mean(homicide), sd_homicide = sd(homicide),
                                             count_burglary = sum(burglary), mean_burglary = 100*mean(burglary), sd_burglary = sd(burglary),
                                             count_shots_fired = sum(shots_fired), mean_shots_fired = 100*mean(shots_fired), sd_shots_fired = sd(shots_fired),
                                             count_assault = sum(assault), mean_assault = 100*mean(assault), sd_assault = sd(assault),
                                             count_rape = sum(rape), mean_rape = 100*mean(rape), sd_rape = sd(rape),
                                             count_theft = sum(theft), mean_theft = 100*mean(theft), sd_theft = sd(theft),
                                             count_counterfeit = sum(counterfeit), mean_counterfeit = 100*mean(counterfeit), sd_counterfeit = sd(counterfeit),
                                             count_reckless_driving = sum(reckless_driving), mean_reckless_driving = 100*mean(reckless_driving), sd_reckless_driving = sd(reckless_driving),
                                             count_lynching = sum(lynching), mean_lynching = 100*mean(lynching), sd_lynching = sd(lynching),
                                             count_vandalism = sum(vandalism), mean_vandalism = 100*mean(vandalism), sd_vandalism = sd(vandalism),
                                             count_order_violation = sum(order_violation), mean_order_violation = 100*mean(order_violation), sd_order_violation = sd(order_violation),
                                             count_kidnapping = sum(kidnapping), mean_kidnapping = 100*mean(kidnapping), sd_kidnapping = sd(kidnapping)) %>% ungroup() %>% 
  mutate(gang_present = as.factor(gang_present), `Presence of Gangs` = ifelse(gang_present == 1, "Yes","No"))


knitr::kable(lapd_crime_lausd_grouped[order(lapd_crime_lausd_grouped$gang_present, lapd_crime_lausd_grouped$year),][-42] , col.names = c('Year', 'Presence of Gangs', 'Count of Robbery', 'Average:Robbery', 'SD:Robbery','Count of Homicide', 'Average:Homicide', 'SD:Homicide', 'Count of Burglary', 'Average:Burglary', 'SD:Burglary','Count of Shots fired', 'Average:Shots fired', 'SD:Shots fired','Count of Assault', 'Average:Assualt', 'SD:Assault','Count of Sexual cases', 'Average:Sexual cases', 'SD:sexual cases','Count of Theft', 'Average:Theft', 'SD:Theft','Count of Counterfeit', 'Average:Counterfeit', 'SD:Counterfeit','Count of Reckless Driving', 'Average:Reckless Driving', 'SD:Reckless Driving','Count of Lynching', 'Average:Lynching', 'SD:Lynching','Count of Vandalism', 'Average:Vandalism', 'SD:Vandalism','Count of Order violation', 'Average:Order violation', 'SD:Order violation','Count of Kidnapping', 'Average:Kidnapping', 'SD:Kidnapping'))
Year Presence of Gangs Count of Robbery Average:Robbery SD:Robbery Count of Homicide Average:Homicide SD:Homicide Count of Burglary Average:Burglary SD:Burglary Count of Shots fired Average:Shots fired SD:Shots fired Count of Assault Average:Assualt SD:Assault Count of Sexual cases Average:Sexual cases SD:sexual cases Count of Theft Average:Theft SD:Theft Count of Counterfeit Average:Counterfeit SD:Counterfeit Count of Reckless Driving Average:Reckless Driving SD:Reckless Driving Count of Lynching Average:Lynching SD:Lynching Count of Vandalism Average:Vandalism SD:Vandalism Count of Order violation Average:Order violation SD:Order violation Count of Kidnapping Average:Kidnapping SD:Kidnapping
2010 0 3283 9.016011 0.3268952 73 0.2004779 0.0465360 13869 38.08805 0.6534659 168 0.4613737 0.0705483 12769 35.06715 0.7168136 1728 4.745558 0.2344820 168 0.4613737 0.0717067 55 0.1510450 0.0388357 10 0.0274627 0.0165698 0 0.0000000 0.0000000 7059 19.38593 0.4614833 1394 3.828303 0.2302648 138 0.3789855 0.0657637
2011 0 2913 8.223935 0.3157559 65 0.1835070 0.0434536 12770 36.05206 0.6304469 152 0.4291240 0.0695528 12172 34.36380 0.7198335 1634 4.613083 0.2400253 173 0.4884108 0.0755471 25 0.0705796 0.0295756 5 0.0141159 0.0140573 1 0.0028232 0.0053134 6737 19.01979 0.4632038 1317 3.718133 0.2207497 135 0.3811298 0.0629784
2012 0 2585 7.280870 0.2942898 83 0.2337765 0.0500136 12617 35.53684 0.6206349 173 0.4872690 0.0735691 11931 33.60466 0.7011088 1692 4.765660 0.2440957 188 0.5295178 0.0917712 41 0.1154799 0.0363662 3 0.0084498 0.0091920 2 0.0056332 0.0106143 6530 18.39229 0.4521115 1298 3.655926 0.2285527 126 0.3548896 0.0599394
2013 0 2302 6.693028 0.2797671 62 0.1802640 0.0430998 12171 35.38699 0.6152779 156 0.4535675 0.0745785 11316 32.90109 0.6874333 1611 4.683956 0.2485992 221 0.6425539 0.1045000 48 0.1395592 0.1168915 4 0.0116299 0.0107837 4 0.0116299 0.0107837 6078 17.67169 0.4416302 1365 3.968716 0.2402295 112 0.3256382 0.0604395
2014 0 2277 6.704750 0.2763943 69 0.2031742 0.0475736 11015 32.43426 0.5951405 170 0.5005742 0.0754158 12450 36.65970 0.7374763 1623 4.779011 0.2379880 235 0.6919702 0.1025835 24 0.0706693 0.0265747 4 0.0117782 0.0132915 1 0.0029446 0.0054264 6283 18.50063 0.4523400 1423 4.190100 0.2570201 111 0.3268455 0.0596014
2015 0 2622 7.416417 0.3067030 79 0.2234542 0.0501246 11947 33.79250 0.6095120 165 0.4667082 0.0763770 13331 37.70719 0.7667874 1665 4.709510 0.2305167 211 0.5968207 0.0809633 25 0.0707134 0.0276265 10 0.0282853 0.0168161 1 0.0028285 0.0053184 6717 18.99926 0.4746515 1179 3.334842 0.2190076 105 0.2969961 0.0564581
2016 0 3088 8.553306 0.3241722 80 0.2215882 0.0556544 13048 36.14104 0.6478491 185 0.5124228 0.0744399 13490 37.36532 0.7746721 1711 4.739218 0.2360689 223 0.6176772 0.0892577 38 0.1052544 0.0332696 16 0.0443176 0.0210474 1 0.0027699 0.0052629 7091 19.64103 0.4747300 1365 3.780849 0.2464861 110 0.3046838 0.0621982
2017 0 3310 9.071724 0.3405616 76 0.2082934 0.0479366 13788 37.78880 0.6691223 189 0.5179927 0.0811076 14215 38.95908 0.7912489 1741 4.771562 0.2380699 228 0.6248801 0.0898535 15 0.0411105 0.0202718 15 0.0411105 0.0202718 1 0.0027407 0.0052352 7199 19.73031 0.4779469 1455 3.987722 0.2344184 89 0.2439225 0.0498814
2018 0 3063 8.537503 0.3260316 64 0.1783873 0.0471881 13238 36.89829 0.6679306 195 0.5435237 0.0807515 14147 39.43195 0.8015650 1673 4.663155 0.2301905 250 0.6968253 0.0932942 21 0.0585333 0.0241869 15 0.0418095 0.0204434 1 0.0027873 0.0052795 7009 19.53619 0.4754454 1465 4.083396 0.2455524 88 0.2452825 0.0516708
2019 0 2801 8.111552 0.3078185 78 0.2258840 0.0492703 11623 33.65961 0.6300870 180 0.5212707 0.0781819 13965 40.44192 0.7929111 1519 4.398946 0.2361838 231 0.6689641 0.0909223 19 0.0550230 0.0234509 7 0.0202716 0.0142366 2 0.0057919 0.0076103 6652 19.26385 0.4744429 1478 4.280212 0.2590241 86 0.2490516 0.0504213
2010 1 5928 13.649865 0.4029925 191 0.4397983 0.0675496 14365 33.07698 0.6111678 391 0.9003201 0.1015084 21707 49.98273 0.8584711 2806 6.461120 0.2763556 256 0.5894679 0.1166062 62 0.1427617 0.0377573 13 0.0299339 0.0275643 2 0.0046052 0.0067861 9399 21.64222 0.4927598 2135 4.916070 0.2614268 270 0.6217044 0.0858832
2011 1 5519 13.160217 0.4022865 182 0.4339843 0.0678768 12940 30.85581 0.5932112 372 0.8870449 0.0972608 20881 49.79135 0.8678692 2643 6.302311 0.2783193 249 0.5937478 0.1232974 39 0.0929966 0.0381278 1 0.0023845 0.0048832 5 0.0119226 0.0109186 8901 21.22469 0.4919175 2026 4.831056 0.2526152 256 0.6104395 0.0857610
2012 1 4852 11.558160 0.3714269 170 0.4049644 0.0678607 12937 30.81779 0.5889404 440 1.0481431 0.1084135 20821 49.59861 0.8595725 2754 6.560423 0.2832251 245 0.5836251 0.1270475 41 0.0976679 0.0348420 6 0.0142929 0.0119546 4 0.0095286 0.0097611 8815 20.99859 0.4835661 2033 4.842898 0.2637673 249 0.5931537 0.0789304
2013 1 4175 10.275405 0.3504507 150 0.3691762 0.0626446 12356 30.41028 0.5790354 361 0.8884842 0.1023707 19716 48.52453 0.8481119 2551 6.278457 0.2717677 314 0.7728089 0.1636085 37 0.0910635 0.0317534 9 0.0221506 0.0148816 6 0.0147670 0.0156876 8558 21.06274 0.4840923 1978 4.868204 0.2639981 211 0.5193079 0.0735688
2014 1 4232 10.330014 0.3519604 163 0.3978715 0.0659814 11526 28.13415 0.5655952 375 0.9153486 0.0997431 21336 52.07967 0.8851366 2552 6.229252 0.2688464 400 0.9763718 0.2448530 26 0.0634642 0.0270535 6 0.0146456 0.0121012 3 0.0073228 0.0110474 8863 21.63396 0.4942015 2245 5.479887 0.2915384 219 0.5345636 0.0768312
2015 1 4581 10.916500 0.3666414 177 0.4217901 0.0683873 12057 28.73177 0.6018268 383 0.9126871 0.1021076 22843 54.43475 0.9246119 2599 6.193404 0.2709221 370 0.8817081 0.1741551 39 0.0929368 0.0312440 14 0.0333619 0.0182624 5 0.0119150 0.0109151 9665 23.03165 0.5213318 1964 4.680202 0.2617075 221 0.5266419 0.0746487
2016 1 5233 12.329477 0.3921199 164 0.3864006 0.0674982 12492 29.43242 0.5932903 475 1.1191480 0.1186692 23540 55.46262 0.9374442 2724 6.418019 0.2773673 424 0.9989869 0.2127905 29 0.0683269 0.0261308 16 0.0376976 0.0194124 6 0.0141366 0.0137285 10413 24.53408 0.5384746 2264 5.334213 0.2864794 199 0.4688641 0.0752087
2017 1 5571 12.934157 0.4090420 162 0.3761144 0.0648956 13144 30.51634 0.6154605 414 0.9611813 0.1111404 24333 56.49378 0.9595904 2625 6.094447 0.2691881 388 0.9008172 0.1579471 22 0.0510773 0.0225948 19 0.0441122 0.0209985 3 0.0069651 0.0083455 10338 24.00167 0.5302642 2345 5.444372 0.2769386 166 0.3854012 0.0638077
2018 1 5226 12.356363 0.3943257 147 0.3475670 0.0616011 12400 29.31858 0.6390255 367 0.8677354 0.0986773 24275 57.39585 0.9653657 2449 5.790419 0.2563451 385 0.9102946 0.1488848 24 0.0567456 0.0238149 20 0.0472880 0.0217409 3 0.0070932 0.0084219 9924 23.46432 0.5224355 2232 5.277344 0.2812823 143 0.3381094 0.0604440
2019 1 4847 11.759140 0.3789501 138 0.3347971 0.0594217 10889 26.41743 0.5603127 423 1.0262258 0.1115246 23653 57.38373 0.9582738 2167 5.257284 0.2571259 421 1.0213736 0.1901742 21 0.0509474 0.0225660 16 0.0388171 0.0196985 2 0.0048521 0.0069656 9674 23.46976 0.5166812 2325 5.640603 0.2892219 158 0.3833184 0.0659722
#define custom color scale
myColors <- brewer.pal(6, "PuOr")
names(myColors) <- levels(sheriff_crime_lausd_grouped$`Presence of Gangs`)
custom_colors <- scale_colour_manual(name = "Presence of Gangs", values = myColors)

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_robbery, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(2,16,1))  +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Robbery (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_homicide, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,1,0.1))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Homicide (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_burglary, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(20,40,2)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Burglary (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_shots_fired, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,1.5,0.1)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Shots Fired (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_assault, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,60,2)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Assault (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_rape, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(1,9,0.5)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Rape (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_theft, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,1,0.1)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Theft (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_counterfeit, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,0.5,0.05)) +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Counterfeit (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_reckless_driving, color = `Presence of Gangs`)) +
  geom_line() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,0.05,0.01))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Reckless Driving (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_lynching, color = `Presence of Gangs`)) +
  geom_line()  + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,0.02,0.005))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Lynching (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_vandalism, color = `Presence of Gangs`)) +
  geom_line() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(0,25,1))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Vandalism (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_order_violation, color = `Presence of Gangs`)) +
  geom_line() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1)) + scale_y_continuous(breaks=seq(3,6,0.5))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Order Violation (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))

lapd_crime_lausd_grouped %>% ggplot(aes(x = year, y = mean_kidnapping, color = `Presence of Gangs`)) +
  geom_line() + theme(legend.title = element_text(size=8)) + 
  ylab("") + scale_x_continuous(breaks=seq(2010,2019,1))  + scale_y_continuous(breaks=seq(0,1,0.1))   +
  custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Kidnapping (x100)") +
  theme(plot.title = element_text(size = 10, face = "bold"))