pckgs <- c("tidyverse", "sf", "dplyr", "tigris","lubridate","purrr","ggplot2","RColorBrewer","hrbrthemes")
lapply(pckgs, library, character.only = T)
# set paths
OS <- .Platform$OS.type
if (OS == "unix"){
input_dir <- "~/Dropbox/chyn_campos_bruhn/Gangs/data"
} else {
input_dir <- "C:/Users/at3981/Dropbox/chyn_campos_bruhn/Gangs/data"
}
Here, I have a dataset of each censusblock-year pair with its distance from a gang. Negative distance means that the gang is inside that census block. Missing values mean that the gang does not exist that year, so I imputed the missing distance value with a proxy positive value.
To locate blocks with gang presence, I did a rowwise operation where if ONLY one distance across the row is found to be negative, the block contains a gang inside. In contrast, census blocks without gang presence are rows where all the distances are postive. I can also found out the number of gangs inside each block by counting the number of distinct negative values within the row.
#load gang distance data
load(str_interp("${input_dir}/gang_distance.rda"))
gang_data <- gang.distance
#fill in missing data with positive values since missing values mean no gangs
gang_data <- gang_data %>% mutate(across(.cols = 3:380, ~case_when(is.na(.) ~ 1, TRUE ~ .)))
#count the number of gangs by counting negative distances across rows
gang_data$no_gang <- rowSums(gang_data[,3:380] <= 0)
#extract blocks with gang presence by finding blocks with any negative distance across rows
block_with_gangs <- gang_data %>% rowwise %>%
filter(any(c(-1,0) %in% sign(c_across(`?????`:Young_Crowd)))) %>% mutate(gang_presence = 1)
#extract blocks without gang presence by finding blocks with all positive distances across rows
block_without_gangs <- gang_data %>% rowwise %>%
filter(all(rep(1,dim(gang_data[,3:380])[2]) == sign(c_across(`?????`:Young_Crowd)))) %>% mutate(gang_presence = 0)
#combine and sort the two data extracts with and without gangs
blocks_gang_presence <- rbind(block_with_gangs,block_without_gangs)
blocks_gang_presence <- blocks_gang_presence %>% select(c("block.id","year","no_gang","gang_presence")) %>%
arrange(block.id, year)
write.csv(blocks_gang_presence, file = str_interp("${input_dir}/block_gang_presence.csv"))
The data now looks like this:
#load yearly data on gang presence - load here instead of using the above output if want to avoid having to run the above trunks again, which takes quite a few minutes
blocks_gang_presence <- read_csv(str_interp("${input_dir}/block_gang_presence.csv")) %>%
rename(census_block = block.id) %>% select(census_block, year, no_gang, gang_presence)
knitr::kable(head(blocks_gang_presence, 10), col.names = c("Census Block ID", "Year","Number of Gangs Inside", "Gang presence"))
| Census Block ID | Year | Number of Gangs Inside | Gang presence |
|---|---|---|---|
| 060371011101000 | 2006 | 0 | 0 |
| 060371011101000 | 2007 | 0 | 0 |
| 060371011101000 | 2008 | 0 | 0 |
| 060371011101000 | 2009 | 0 | 0 |
| 060371011101000 | 2011 | 0 | 0 |
| 060371011101000 | 2016 | 0 | 0 |
| 060371011101000 | 2019 | 0 | 0 |
| 060371011101001 | 2006 | 0 | 0 |
| 060371011101001 | 2007 | 0 | 0 |
| 060371011101001 | 2008 | 0 | 0 |
First, I collapsed the monthly crime data into a yearly dataset so that I can merge it with the yearly gang presence data.
Note that the yearly data on gang presence covers the year 2006, 2007, 2008, 2009, 2011, 2016, 2019. However, our crime data covers the year 2010-2019 (LAPD) and 2005-2021 (LA Sheriff). Therefore, simply merging 1:1 on years and census block id will get a lot of crime data being thrown away. To avoid this, I imputed the missing gang presence value in years we do not have data by the closest earlier gang presence value of that particular census block. For example, gang presence data from the year 2013 will come from the gang presence data of the year 2011. Note that we do not have gang presence data on year 2005 so that year data from the Sheriff crime data will be unmerged.
After filling in, there will still be missing values from observations who only have one year of data and that year is not covered by the gang presence data. Thus, there is no other observations for us to impute and I removed those observations.
#load LAPD crime data
lapd_crime <- read_csv(str_interp("${input_dir}/crime/LAPD/output/panel_data_crimela_1019.csv"))
#collapse monthly data to yearly data.
lapd_crime_yearly <- lapd_crime %>% group_by(census_block, year) %>%
summarize(robbery = sum(robbery), homicide = sum(homicide), burglary = sum(burglary),
shots_fired = sum(shots_fired), assault = sum(assault), rape = sum(rape),
theft = sum(theft), reckless_driving = sum(reckless_driving),
vandalism = sum(vandalism), kidnapping = sum(kidnapping), order_violation = sum(order_violation),
lynching = sum(lynching), counterfeit = sum(counterfeit), vandalism = sum(vandalism)) %>%
ungroup() %>% arrange(census_block, year)
#fill in the missing values with the closest earlier year
#change 2009 rto 2010 so that the 2009 gang presence data can be merged in with the 2010 LAPD crime data
blocks_gang_presence2 <- blocks_gang_presence %>% mutate(year = case_when(year == 2009 ~ 2010, TRUE ~ year))
lapd_crime_gang <- lapd_crime_yearly %>%
left_join(blocks_gang_presence2, by = c("census_block","year")) %>% group_by(census_block) %>%
fill(c(gang_presence, no_gang), .direction = "down") %>% ungroup() %>% drop_na(gang_presence)
Here, I documented the number of census block with and without gangs over the year.
lapd_crime_total <- lapd_crime_gang %>% group_by(year, gang_presence) %>% tally()
knitr::kable(lapd_crime_total, col.names = c("Year", "Presence of Gangs","Number of Census Blocks"))
| Year | Presence of Gangs | Number of Census Blocks |
|---|---|---|
| 2010 | 0 | 7080 |
| 2010 | 1 | 7527 |
| 2011 | 0 | 6701 |
| 2011 | 1 | 7834 |
| 2012 | 0 | 6430 |
| 2012 | 1 | 7621 |
| 2013 | 0 | 6319 |
| 2013 | 1 | 7573 |
| 2014 | 0 | 6292 |
| 2014 | 1 | 7533 |
| 2015 | 0 | 6231 |
| 2015 | 1 | 7532 |
| 2016 | 0 | 7323 |
| 2016 | 1 | 7112 |
| 2017 | 0 | 7113 |
| 2017 | 1 | 7103 |
| 2018 | 0 | 7069 |
| 2018 | 1 | 7095 |
| 2019 | 0 | 6484 |
| 2019 | 1 | 8175 |
After merging the data, I collapsed it on the year and gang presence variable to calculate some summary statistics of different crime types. Specifically, I calculated the sum, mean, and standard deviation. Note that the mean for a given crime type here is calculated as:
\[ \overline{Crime_{kjt}} = \frac{\sum_i Case_{ikjt}}{\sum_{j \in \{J_0,J_1\}} Block_{jt}} \] where the subscript \(i\) denotes a particular case of that crime type \(k\) in blocks of gang presence status \(j\), and \(t\) denotes 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 cases of that crime type within all the census blocks with/without gang presence, divided by the number of census blocks with/without gang presence. For illustration purposes, I multiplied all of these mean by 100.
lapd_crime_grouped <- lapd_crime_gang %>%
group_by(year, gang_presence) %>% 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_presence), `Presence of Gangs` = ifelse(gang_presence == 1, "Yes","No"))
knitr::kable(lapd_crime_grouped[,1:41] , 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 | 2573 | 36.34181 | 1.1024588 | 50 | 0.7062147 | 0.0902406 | 12843 | 181.3983 | 2.764986 | 104 | 1.468927 | 0.1282701 | 10287 | 145.2966 | 2.993621 | 1417 | 20.01412 | 0.5977544 | 278 | 3.926554 | 0.7800200 | 51 | 0.7203390 | 0.0894432 | 9 | 0.1271186 | 0.0356335 | 0 | 0.0000000 | 0.0000000 | 6008 | 84.85876 | 1.525953 | 1167 | 16.48305 | 0.6993875 | 128 | 1.8079096 | 0.1394629 |
| 2010 | 1 | 5776 | 76.73708 | 1.7205696 | 187 | 2.4843895 | 0.1606996 | 13823 | 183.6455 | 2.513151 | 385 | 5.114920 | 0.2570576 | 20695 | 274.9435 | 4.369638 | 2698 | 35.84429 | 0.8367173 | 252 | 3.347947 | 0.7619683 | 48 | 0.6377043 | 0.0796066 | 12 | 0.1594261 | 0.0651873 | 3 | 0.0398565 | 0.0199614 | 9062 | 120.39325 | 1.840792 | 2007 | 26.66401 | 0.9159360 | 258 | 3.4276604 | 0.2059301 |
| 2011 | 0 | 2045 | 30.51783 | 0.9478105 | 42 | 0.6267721 | 0.0826219 | 11516 | 171.8549 | 2.689926 | 85 | 1.268467 | 0.1269162 | 8949 | 133.5472 | 2.932470 | 1229 | 18.34055 | 0.6049047 | 283 | 4.223250 | 0.7810296 | 29 | 0.4327712 | 0.0761719 | 6 | 0.0895389 | 0.0345431 | 1 | 0.0149231 | 0.0122160 | 5348 | 79.80898 | 1.553514 | 1014 | 15.13207 | 0.6872572 | 89 | 1.3281600 | 0.1183329 |
| 2011 | 1 | 5548 | 70.81950 | 1.7290237 | 184 | 2.3487363 | 0.1620430 | 13317 | 169.9898 | 2.432688 | 385 | 4.914475 | 0.2412993 | 20751 | 264.8838 | 4.265822 | 2616 | 33.39290 | 0.8050366 | 259 | 3.306102 | 0.7880472 | 45 | 0.5744192 | 0.0963667 | 3 | 0.0382946 | 0.0195665 | 4 | 0.0510595 | 0.0225920 | 9008 | 114.98596 | 1.837732 | 2037 | 26.00204 | 0.8047905 | 261 | 3.3316314 | 0.2041021 |
| 2012 | 0 | 1868 | 29.05132 | 0.9536890 | 52 | 0.8087092 | 0.0929791 | 11109 | 172.7683 | 2.679899 | 93 | 1.446345 | 0.1352799 | 8621 | 134.0747 | 2.881828 | 1239 | 19.26905 | 0.5794018 | 276 | 4.292380 | 0.7999604 | 43 | 0.6687403 | 0.1134263 | 4 | 0.0622084 | 0.0249358 | 2 | 0.0311042 | 0.0249416 | 5251 | 81.66407 | 1.524458 | 974 | 15.14774 | 0.7741006 | 85 | 1.3219285 | 0.1169134 |
| 2012 | 1 | 4867 | 63.86301 | 1.5695924 | 182 | 2.3881380 | 0.1650792 | 13047 | 171.1980 | 2.408286 | 422 | 5.537331 | 0.2663628 | 20653 | 271.0012 | 4.392925 | 2716 | 35.63837 | 0.8407332 | 248 | 3.254166 | 0.7266875 | 38 | 0.4986222 | 0.0740739 | 6 | 0.0787298 | 0.0280496 | 4 | 0.0524866 | 0.0229054 | 8787 | 115.29983 | 1.787225 | 1949 | 25.57407 | 0.8160594 | 252 | 3.3066527 | 0.1969809 |
| 2013 | 0 | 1690 | 26.74474 | 0.9178003 | 39 | 0.6171863 | 0.0803200 | 10770 | 170.4384 | 2.650765 | 78 | 1.234373 | 0.1187124 | 8325 | 131.7455 | 2.837846 | 1209 | 19.13277 | 0.6461326 | 314 | 4.969141 | 0.8326585 | 49 | 0.7754392 | 0.2763840 | 1 | 0.0158253 | 0.0125799 | 2 | 0.0316506 | 0.0177892 | 4863 | 76.95838 | 1.505846 | 985 | 15.58791 | 0.7495339 | 89 | 1.4084507 | 0.1293729 |
| 2013 | 1 | 4191 | 55.34134 | 1.4564303 | 156 | 2.0599498 | 0.1501832 | 12519 | 165.3110 | 2.395787 | 365 | 4.819754 | 0.2737426 | 19551 | 258.1672 | 4.269617 | 2503 | 33.05163 | 0.7797386 | 326 | 4.304767 | 1.0887679 | 35 | 0.4621682 | 0.0734392 | 10 | 0.1320481 | 0.0363168 | 6 | 0.0792288 | 0.0363322 | 8618 | 113.79902 | 1.822585 | 1952 | 25.77578 | 0.8249331 | 210 | 2.7730094 | 0.1788384 |
| 2014 | 0 | 1607 | 25.54037 | 0.8490007 | 44 | 0.6993007 | 0.0974091 | 9625 | 152.9720 | 2.445510 | 95 | 1.509854 | 0.1390099 | 9173 | 145.7883 | 3.210365 | 1249 | 19.85060 | 0.6395369 | 321 | 5.101717 | 0.7535877 | 25 | 0.3973299 | 0.0629138 | 3 | 0.0476796 | 0.0281879 | 1 | 0.0158932 | 0.0126068 | 5031 | 79.95868 | 1.571497 | 1087 | 17.27591 | 0.8944637 | 80 | 1.2714558 | 0.1215742 |
| 2014 | 1 | 4266 | 56.63082 | 1.4708230 | 163 | 2.1638126 | 0.1569225 | 11587 | 153.8165 | 2.239221 | 376 | 4.991371 | 0.2595066 | 21152 | 280.7912 | 4.592835 | 2543 | 33.75813 | 0.7781307 | 410 | 5.442719 | 1.7123805 | 26 | 0.3451480 | 0.0630166 | 8 | 0.1061994 | 0.0325731 | 3 | 0.0398248 | 0.0257619 | 8928 | 118.51852 | 1.846854 | 2227 | 29.56326 | 0.9457276 | 212 | 2.8142838 | 0.1865192 |
| 2015 | 0 | 1871 | 30.02728 | 1.1108100 | 38 | 0.6098540 | 0.0818802 | 10317 | 165.5753 | 2.660048 | 82 | 1.316001 | 0.1427324 | 9730 | 156.1547 | 3.467856 | 1284 | 20.60664 | 0.6669702 | 334 | 5.360295 | 0.8134204 | 25 | 0.4012197 | 0.0657097 | 8 | 0.1283903 | 0.0358115 | 0 | 0.0000000 | 0.0000000 | 5107 | 81.96116 | 1.680272 | 795 | 12.75879 | 0.6744081 | 69 | 1.1073664 | 0.1120622 |
| 2015 | 1 | 4633 | 61.51089 | 1.5783525 | 182 | 2.4163569 | 0.1715382 | 12121 | 160.9267 | 2.503353 | 392 | 5.204461 | 0.2554930 | 22800 | 302.7084 | 5.016749 | 2559 | 33.97504 | 0.8410825 | 386 | 5.124801 | 1.1811278 | 36 | 0.4779607 | 0.0708729 | 19 | 0.2522570 | 0.0527457 | 5 | 0.0663834 | 0.0257581 | 9638 | 127.96070 | 2.064655 | 1916 | 25.43813 | 0.8055218 | 223 | 2.9607010 | 0.1866610 |
| 2016 | 0 | 2267 | 30.95726 | 1.0677154 | 55 | 0.7510583 | 0.1087455 | 12172 | 166.2160 | 2.893922 | 118 | 1.611361 | 0.1332973 | 10311 | 140.8029 | 3.316312 | 1405 | 19.18613 | 0.6514576 | 303 | 4.137649 | 0.6638172 | 36 | 0.4916018 | 0.0737483 | 16 | 0.2184897 | 0.0466950 | 1 | 0.0136556 | 0.0116857 | 5990 | 81.79708 | 1.695647 | 1060 | 14.47494 | 0.6278789 | 87 | 1.1880377 | 0.1258494 |
| 2016 | 1 | 5327 | 74.90157 | 1.8438171 | 171 | 2.4043870 | 0.1697436 | 11963 | 168.2087 | 2.610414 | 469 | 6.594488 | 0.3065111 | 23244 | 326.8279 | 5.196817 | 2687 | 37.78121 | 0.8755992 | 446 | 6.271091 | 1.5811624 | 27 | 0.3796400 | 0.0615022 | 15 | 0.2109111 | 0.0458798 | 5 | 0.0703037 | 0.0313671 | 10117 | 142.25253 | 2.260285 | 2124 | 29.86502 | 1.0024346 | 205 | 2.8824522 | 0.1952505 |
| 2017 | 0 | 2470 | 34.72515 | 1.1552862 | 55 | 0.7732321 | 0.0967517 | 13088 | 184.0011 | 3.097541 | 118 | 1.658934 | 0.1537141 | 11002 | 154.6745 | 3.492936 | 1471 | 20.68044 | 0.6685518 | 275 | 3.866161 | 0.4411943 | 20 | 0.2811753 | 0.0555469 | 12 | 0.1687052 | 0.0410420 | 0 | 0.0000000 | 0.0000000 | 6116 | 85.98341 | 1.787866 | 1089 | 15.31000 | 0.6510218 | 88 | 1.2371714 | 0.1214550 |
| 2017 | 1 | 5536 | 77.93890 | 1.9476861 | 154 | 2.1680980 | 0.1594931 | 12675 | 178.4457 | 2.867166 | 395 | 5.561031 | 0.2957109 | 23939 | 337.0266 | 5.485371 | 2557 | 35.99887 | 0.8721826 | 398 | 5.603266 | 1.0650286 | 22 | 0.3097283 | 0.0555709 | 17 | 0.2393355 | 0.0488668 | 4 | 0.0563142 | 0.0237256 | 10002 | 140.81374 | 2.218297 | 2250 | 31.67676 | 0.9693466 | 170 | 2.3933549 | 0.1618028 |
| 2018 | 0 | 2372 | 33.55496 | 1.1169627 | 50 | 0.7073136 | 0.0978304 | 12664 | 179.1484 | 3.168237 | 133 | 1.881454 | 0.1589161 | 11421 | 161.5646 | 3.984703 | 1451 | 20.52624 | 0.6719335 | 320 | 4.526807 | 0.5550502 | 16 | 0.2263404 | 0.0557449 | 11 | 0.1556090 | 0.0394194 | 0 | 0.0000000 | 0.0000000 | 5972 | 84.48154 | 1.732490 | 1152 | 16.29651 | 0.7079331 | 69 | 0.9760928 | 0.0997496 |
| 2018 | 1 | 5244 | 73.91121 | 1.7962188 | 153 | 2.1564482 | 0.1564787 | 12140 | 171.1064 | 2.688553 | 343 | 4.834390 | 0.2422809 | 23882 | 336.6032 | 5.399235 | 2410 | 33.96758 | 0.8118259 | 391 | 5.510923 | 0.9873354 | 25 | 0.3523608 | 0.0592595 | 20 | 0.2818887 | 0.0530220 | 3 | 0.0422833 | 0.0205600 | 9790 | 137.98450 | 2.157373 | 2185 | 30.79634 | 0.9763268 | 146 | 2.0577872 | 0.1543449 |
| 2019 | 0 | 1910 | 29.45713 | 1.0548266 | 41 | 0.6323257 | 0.0867078 | 10248 | 158.0506 | 2.956651 | 94 | 1.449722 | 0.1397632 | 9602 | 148.0876 | 4.043048 | 1115 | 17.19618 | 0.6149034 | 281 | 4.333745 | 0.6762563 | 21 | 0.3238742 | 0.0568221 | 6 | 0.0925355 | 0.0304079 | 2 | 0.0308452 | 0.0175614 | 4890 | 75.41641 | 1.662395 | 933 | 14.38927 | 0.6403989 | 64 | 0.9870450 | 0.1004143 |
| 2019 | 1 | 5167 | 63.20489 | 1.5902506 | 152 | 1.8593272 | 0.1455539 | 11770 | 143.9755 | 2.345601 | 450 | 5.504587 | 0.2774516 | 25210 | 308.3792 | 5.099686 | 2315 | 28.31804 | 0.7179612 | 451 | 5.516820 | 1.1709789 | 21 | 0.2568807 | 0.0529830 | 19 | 0.2324159 | 0.0481564 | 2 | 0.0244648 | 0.0156403 | 10351 | 126.61774 | 2.024284 | 2442 | 29.87156 | 0.9475179 | 173 | 2.1162080 | 0.1638101 |
#define custom color scale
myColors <- brewer.pal(6, "PuOr")
names(myColors) <- levels(lapd_crime_grouped$`Presence of Gangs`)
custom_colors <- scale_colour_manual(name = "Presence of Gangs", values = myColors)
#plots of average cases of crimes reported by LAPD
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Robbery (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Homicide (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Burglary (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Shots Fired (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Assault (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Rape (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Theft (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Counterfeit (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Reckless Driving (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Lynching (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Vandalism (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Order Violation (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
lapd_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LAPD - Average Cases of Kidnapping (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
The below section repeats all the same steps with the Sheriff crime data. However, it seems that there are very few census blocks with gang presence in this data. This means that the count of crimes in census blocks without gang presence is much larger than the corresponding figure from blocks with gangs. Even when taking the mean, the pattern still holds for all crime types.
#Sheriff Crime Data
sheriff_crime <- read_csv(str_interp("${input_dir}/crime/Sheriff/output/panel_data_crimela_0521.csv"))
#collapse to yearly data
sheriff_crime_yearly <- sheriff_crime %>% group_by(census_block, year) %>%
summarize(robbery = sum(robbery), homicide = sum(homicide), burglary = sum(burglary),
weapons = sum(weapons), assault = sum(assault), rape_sexual = sum(rape_sexual),
theft = sum(theft), reckless_driving = sum(reckless_driving), fraud = sum(fraud),
vandalism = sum(vandalism), alcohol = sum(alcohol)) %>%
ungroup() %>% arrange(census_block, year)
#join with gang presnce data
sheriff_crime_gang <- sheriff_crime_yearly %>%
left_join(blocks_gang_presence, by = c("census_block","year")) %>% group_by(census_block) %>%
fill(c(gang_presence), .direction = "down") %>% ungroup() %>% drop_na(gang_presence)
sheriff_crime_total <- sheriff_crime_gang %>% group_by(year, gang_presence) %>% tally()
knitr::kable(sheriff_crime_total, col.names = c("Year", "Presence of Gangs","Number of Census Blocks"))
| Year | Presence of Gangs | Number of Census Blocks |
|---|---|---|
| 2006 | 0 | 2849 |
| 2006 | 1 | 731 |
| 2007 | 0 | 3006 |
| 2007 | 1 | 869 |
| 2008 | 0 | 2839 |
| 2008 | 1 | 1023 |
| 2009 | 0 | 2769 |
| 2009 | 1 | 922 |
| 2010 | 0 | 2635 |
| 2010 | 1 | 639 |
| 2011 | 0 | 2799 |
| 2011 | 1 | 1308 |
| 2012 | 0 | 2565 |
| 2012 | 1 | 938 |
| 2013 | 0 | 2516 |
| 2013 | 1 | 920 |
| 2014 | 0 | 2495 |
| 2014 | 1 | 909 |
| 2015 | 0 | 2527 |
| 2015 | 1 | 885 |
| 2016 | 0 | 2713 |
| 2016 | 1 | 1158 |
| 2017 | 0 | 2501 |
| 2017 | 1 | 794 |
| 2018 | 0 | 2414 |
| 2018 | 1 | 658 |
| 2019 | 0 | 2745 |
| 2019 | 1 | 611 |
| 2020 | 0 | 2614 |
| 2020 | 1 | 475 |
| 2021 | 0 | 2605 |
| 2021 | 1 | 419 |
sheriff_crime_grouped <- sheriff_crime_gang %>% group_by(year, gang_presence) %>% 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_weapons = sum(weapons), mean_weapons = 100*mean(weapons), sd_weapons = sd(weapons),
count_assault = sum(assault), mean_assault = 100*mean(assault), sd_assault = sd(assault),
count_rape_sexual = sum(rape_sexual), mean_rape_sexual = 100*mean(rape_sexual), sd_rape_sexual = sd(rape_sexual),
count_theft = sum(theft), mean_theft = 100*mean(theft), sd_theft = sd(theft),
count_reckless_driving = sum(reckless_driving), mean_reckless_driving = 100*mean(reckless_driving), sd_reckless_driving = sd(reckless_driving),
count_fraud = sum(fraud), mean_fraud = 100*mean(fraud), sd_fraud = sd(fraud),
count_vandalism = sum(vandalism), mean_vandalism = 100*mean(vandalism), sd_vandalism = sd(vandalism),
count_alcohol = sum(alcohol), mean_alcohol = 100*mean(alcohol), sd_alcohol = sd(alcohol)) %>% ungroup() %>%
mutate(gang_presence = as.factor(gang_presence), `Presence of Gangs` = ifelse(gang_presence == 1, "Yes","No"))
knitr::kable(sheriff_crime_grouped[-36], 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 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 Reckless Driving', 'Average:Reckless Driving', 'SD:Reckless Driving','Count of Fraud', 'Average:Fraud', 'SD:Fraud','Count of Vandalism', 'Average:Vandalism', 'SD:Vandalism','Count of Alcohol', 'Average:Alcohol', 'SD:Alcohol'))
| 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 Reckless Driving | Average:Reckless Driving | SD:Reckless Driving | Count of Fraud | Average:Fraud | SD:Fraud | Count of Vandalism | Average:Vandalism | SD:Vandalism | Count of Alcohol | Average:Alcohol | SD:Alcohol |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 | 0 | 1183 | 41.523342 | 1.1304920 | 69 | 2.4219024 | 0.1668959 | 1666 | 58.476658 | 1.1815201 | 943 | 33.099333 | 3.4583636 | 2845 | 99.85960 | 20.7569874 | 434 | 15.233415 | 0.9145145 | 3630 | 127.41313 | 4.561260 | 282 | 9.8982099 | 0.5287012 | 922 | 32.362232 | 0.7720586 | 2180 | 76.51808 | 3.3971602 | 647 | 22.709723 | 1.1477977 |
| 2006 | 1 | 93 | 12.722298 | 0.5429098 | 0 | 0.0000000 | 0.0000000 | 65 | 8.891929 | 0.4843019 | 59 | 8.071135 | 0.3356409 | 173 | 23.66621 | 0.8226731 | 31 | 4.240766 | 0.2711855 | 208 | 28.45417 | 2.298545 | 17 | 2.3255814 | 0.1596428 | 51 | 6.976744 | 0.2654587 | 253 | 34.61012 | 2.1938383 | 10 | 1.367989 | 0.1162378 |
| 2007 | 0 | 1266 | 42.115769 | 1.2504661 | 60 | 1.9960080 | 0.1445659 | 1797 | 59.780439 | 1.1325975 | 936 | 31.137725 | 3.4894922 | 2791 | 92.84764 | 18.0143373 | 465 | 15.469062 | 0.6047700 | 4171 | 138.75582 | 5.901902 | 292 | 9.7139055 | 0.4229818 | 1031 | 34.298071 | 0.8205730 | 2365 | 78.67598 | 3.2522519 | 767 | 25.515635 | 1.1247178 |
| 2007 | 1 | 122 | 14.039125 | 0.6447879 | 0 | 0.0000000 | 0.0000000 | 87 | 10.011508 | 0.4429296 | 83 | 9.551208 | 0.3856177 | 160 | 18.41197 | 0.7639191 | 22 | 2.531646 | 0.1712082 | 260 | 29.91945 | 1.548081 | 23 | 2.6467204 | 0.1743694 | 42 | 4.833141 | 0.2301324 | 574 | 66.05293 | 6.9829331 | 37 | 4.257767 | 0.2434029 |
| 2008 | 0 | 1169 | 41.176471 | 1.1686001 | 53 | 1.8668545 | 0.1404846 | 1869 | 65.833040 | 1.3059980 | 988 | 34.800986 | 4.2856993 | 2622 | 92.35646 | 18.4437550 | 508 | 17.893625 | 0.7135802 | 4119 | 145.08630 | 4.898508 | 302 | 10.6375484 | 0.4543559 | 1122 | 39.520958 | 0.9645906 | 2258 | 79.53505 | 3.4678681 | 965 | 33.990842 | 1.2886708 |
| 2008 | 1 | 155 | 15.151515 | 0.7305971 | 7 | 0.6842620 | 0.0824770 | 106 | 10.361681 | 0.6931427 | 128 | 12.512219 | 0.7520255 | 304 | 29.71652 | 3.3088953 | 31 | 3.030303 | 0.1825579 | 352 | 34.40860 | 2.630337 | 30 | 2.9325513 | 0.1905811 | 87 | 8.504399 | 0.2927720 | 335 | 32.74682 | 2.2346012 | 55 | 5.376344 | 0.2542073 |
| 2009 | 0 | 1075 | 38.822680 | 1.0911587 | 40 | 1.4445648 | 0.1252486 | 1827 | 65.980498 | 1.3729341 | 840 | 30.335861 | 4.7254530 | 2449 | 88.44348 | 18.2975272 | 410 | 14.806790 | 0.6068290 | 4108 | 148.35681 | 6.653574 | 255 | 9.2091008 | 0.4092133 | 965 | 34.850126 | 0.9470627 | 2172 | 78.43987 | 3.7288075 | 744 | 26.868906 | 1.4332568 |
| 2009 | 1 | 146 | 15.835141 | 0.7859244 | 2 | 0.2169197 | 0.0465494 | 71 | 7.700651 | 0.4882246 | 155 | 16.811280 | 2.5200483 | 277 | 30.04338 | 3.1263268 | 30 | 3.253796 | 0.2004985 | 255 | 27.65727 | 1.923192 | 13 | 1.4099783 | 0.1268370 | 51 | 5.531453 | 0.2425412 | 262 | 28.41649 | 2.0074640 | 36 | 3.904555 | 0.2648302 |
| 2010 | 0 | 1139 | 43.225806 | 1.1999522 | 54 | 2.0493359 | 0.1545235 | 1926 | 73.092979 | 1.2848379 | 777 | 29.487666 | 3.3034278 | 2454 | 93.13093 | 15.0900432 | 441 | 16.736243 | 0.9199537 | 4052 | 153.77609 | 7.739421 | 304 | 11.5370019 | 0.5332268 | 945 | 35.863378 | 1.0177042 | 1876 | 71.19545 | 1.9823034 | 799 | 30.322581 | 1.1808267 |
| 2010 | 1 | 111 | 17.370892 | 0.7012286 | 3 | 0.4694836 | 0.0684114 | 95 | 14.866980 | 0.6394506 | 99 | 15.492958 | 1.1927563 | 234 | 36.61972 | 2.5804637 | 31 | 4.851330 | 0.2221867 | 293 | 45.85290 | 2.411652 | 16 | 2.5039124 | 0.2079885 | 45 | 7.042254 | 0.3010717 | 203 | 31.76839 | 1.4233334 | 53 | 8.294210 | 0.6089768 |
| 2011 | 0 | 901 | 32.190068 | 0.9626639 | 28 | 1.0003573 | 0.1161078 | 1703 | 60.843158 | 1.1707113 | 624 | 22.293676 | 1.7865841 | 2117 | 75.63416 | 12.2659041 | 390 | 13.933548 | 0.6841562 | 4360 | 155.76992 | 7.124203 | 341 | 12.1829225 | 0.5503447 | 876 | 31.296892 | 0.9207013 | 1604 | 57.30618 | 1.7508100 | 674 | 24.080029 | 1.1693153 |
| 2011 | 1 | 250 | 19.113150 | 0.6765371 | 13 | 0.9938838 | 0.0992350 | 331 | 25.305810 | 0.7601583 | 202 | 15.443425 | 0.4876472 | 360 | 27.52294 | 0.8357530 | 66 | 5.045872 | 0.2514985 | 709 | 54.20489 | 2.803251 | 43 | 3.2874618 | 0.2170724 | 91 | 6.957186 | 0.2662744 | 331 | 25.30581 | 0.6737156 | 126 | 9.633028 | 0.5983031 |
| 2012 | 0 | 952 | 37.115010 | 1.0293405 | 22 | 0.8576998 | 0.0922320 | 1729 | 67.407407 | 1.3379038 | 609 | 23.742690 | 1.9006534 | 2538 | 98.94737 | 18.8906938 | 393 | 15.321637 | 0.7807118 | 4635 | 180.70175 | 7.431263 | 307 | 11.9688109 | 0.5409357 | 996 | 38.830409 | 0.9793598 | 1581 | 61.63743 | 2.3188262 | 759 | 29.590643 | 1.1458409 |
| 2012 | 1 | 260 | 27.718550 | 1.0340684 | 9 | 0.9594883 | 0.0975344 | 319 | 34.008529 | 0.8434017 | 144 | 15.351812 | 0.4641852 | 449 | 47.86780 | 1.3548890 | 80 | 8.528785 | 0.3566370 | 753 | 80.27719 | 3.759089 | 15 | 1.5991471 | 0.1337423 | 125 | 13.326226 | 0.4871258 | 308 | 32.83582 | 0.8087473 | 170 | 18.123667 | 1.1564813 |
| 2013 | 0 | 801 | 31.836248 | 0.9604488 | 30 | 1.1923688 | 0.1085643 | 1662 | 66.057234 | 1.2611536 | 622 | 24.721781 | 2.2658525 | 2815 | 111.88394 | 26.1396575 | 354 | 14.069952 | 0.9302071 | 4125 | 163.95072 | 4.933193 | 258 | 10.2543720 | 0.5553083 | 877 | 34.856916 | 0.8363760 | 1588 | 63.11606 | 3.9178298 | 728 | 28.934817 | 1.2068978 |
| 2013 | 1 | 282 | 30.652174 | 1.1557496 | 11 | 1.1956522 | 0.1087493 | 313 | 34.021739 | 0.9437452 | 143 | 15.543478 | 0.4508158 | 464 | 50.43478 | 1.5577329 | 77 | 8.369565 | 0.3882881 | 912 | 99.13043 | 5.495268 | 19 | 2.0652174 | 0.1497463 | 113 | 12.282609 | 0.4390125 | 344 | 37.39130 | 1.0675620 | 162 | 17.608696 | 1.0987548 |
| 2014 | 0 | 758 | 30.380761 | 0.9318635 | 18 | 0.7214429 | 0.0846478 | 1424 | 57.074148 | 1.0430324 | 586 | 23.486974 | 2.6105368 | 3131 | 125.49098 | 29.6136840 | 328 | 13.146293 | 0.7494666 | 4025 | 161.32265 | 5.654010 | 241 | 9.6593186 | 0.4599959 | 809 | 32.424850 | 0.7715581 | 1611 | 64.56914 | 4.3191073 | 650 | 26.052104 | 1.1594356 |
| 2014 | 1 | 259 | 28.492849 | 1.0299499 | 14 | 1.5401540 | 0.1232113 | 332 | 36.523652 | 1.0004082 | 136 | 14.961496 | 0.5264506 | 516 | 56.76568 | 1.4021259 | 63 | 6.930693 | 0.2866979 | 797 | 87.67877 | 3.669166 | 24 | 2.6402640 | 0.2028604 | 107 | 11.771177 | 0.3760519 | 409 | 44.99450 | 1.3581912 | 190 | 20.902090 | 1.0957899 |
| 2015 | 0 | 711 | 28.136130 | 0.8886885 | 26 | 1.0288880 | 0.1120819 | 1402 | 55.480807 | 1.1181507 | 669 | 26.474080 | 3.2833880 | 3441 | 136.16937 | 33.3922643 | 296 | 11.713494 | 0.7341161 | 4266 | 168.81678 | 6.035402 | 184 | 7.2813613 | 0.4002188 | 875 | 34.626039 | 0.8497641 | 1824 | 72.18045 | 4.9852287 | 446 | 17.649387 | 0.8264443 |
| 2015 | 1 | 273 | 30.847458 | 1.0072062 | 13 | 1.4689266 | 0.1203738 | 233 | 26.327684 | 0.8426261 | 159 | 17.966102 | 0.5790790 | 507 | 57.28814 | 1.4662682 | 81 | 9.152542 | 0.4195268 | 780 | 88.13559 | 4.653192 | 15 | 1.6949153 | 0.1376342 | 111 | 12.542373 | 0.4134038 | 383 | 43.27684 | 1.5636024 | 135 | 15.254237 | 0.8875756 |
| 2016 | 0 | 895 | 32.989311 | 0.9824691 | 39 | 1.4375230 | 0.1190538 | 1381 | 50.903059 | 1.1239595 | 749 | 27.607814 | 2.8273982 | 3703 | 136.49097 | 34.0119748 | 325 | 11.979359 | 1.0736292 | 4788 | 176.48360 | 5.160905 | 153 | 5.6395135 | 0.2952247 | 890 | 32.805013 | 0.7903444 | 2148 | 79.17435 | 4.9036188 | 1019 | 37.559897 | 7.2047659 |
| 2016 | 1 | 331 | 28.583765 | 1.2411790 | 9 | 0.7772021 | 0.0878538 | 240 | 20.725389 | 0.6795310 | 151 | 13.039724 | 0.4191917 | 550 | 47.49568 | 1.4789721 | 71 | 6.131261 | 0.3092451 | 866 | 74.78411 | 3.604517 | 14 | 1.2089810 | 0.1309190 | 107 | 9.240069 | 0.3541495 | 451 | 38.94646 | 1.3269859 | 121 | 10.449050 | 0.9400145 |
| 2017 | 0 | 954 | 38.144742 | 1.1214453 | 29 | 1.1595362 | 0.1070770 | 1501 | 60.015994 | 1.2958642 | 762 | 30.467813 | 2.8617362 | 3337 | 133.42663 | 31.3245881 | 348 | 13.914434 | 1.2012623 | 4516 | 180.56777 | 5.815137 | 141 | 5.6377449 | 0.2764422 | 777 | 31.067573 | 0.7614736 | 1998 | 79.88804 | 4.4270910 | 764 | 30.547781 | 3.7851613 |
| 2017 | 1 | 204 | 25.692695 | 0.7394375 | 8 | 1.0075567 | 0.0999331 | 218 | 27.455919 | 0.7500703 | 172 | 21.662468 | 0.5712098 | 404 | 50.88161 | 2.0095730 | 52 | 6.549118 | 0.2897894 | 667 | 84.00504 | 3.649990 | 9 | 1.1335013 | 0.1059276 | 95 | 11.964735 | 0.3851491 | 416 | 52.39295 | 1.7939387 | 74 | 9.319899 | 0.6323591 |
| 2018 | 0 | 808 | 33.471417 | 1.0136963 | 25 | 1.0356255 | 0.1012583 | 1237 | 51.242751 | 1.0465991 | 759 | 31.441591 | 3.2275466 | 3598 | 149.04722 | 37.7353495 | 308 | 12.758906 | 1.0922442 | 4624 | 191.54930 | 7.340986 | 205 | 8.4921292 | 0.4568361 | 743 | 30.778790 | 0.7816571 | 1762 | 72.99089 | 4.5082188 | 508 | 21.043910 | 1.3901401 |
| 2018 | 1 | 151 | 22.948328 | 0.6601831 | 5 | 0.7598784 | 0.0869052 | 179 | 27.203647 | 0.7805722 | 159 | 24.164134 | 0.6853312 | 338 | 51.36778 | 2.3680962 | 23 | 3.495441 | 0.2213699 | 623 | 94.68085 | 3.512348 | 7 | 1.0638298 | 0.1165559 | 82 | 12.462006 | 0.3857846 | 347 | 52.73556 | 1.5712445 | 55 | 8.358663 | 0.4455133 |
| 2019 | 0 | 901 | 32.823315 | 1.0328535 | 32 | 1.1657559 | 0.1073586 | 1128 | 41.092896 | 0.8942789 | 863 | 31.438980 | 2.9831696 | 3081 | 112.24044 | 23.4843543 | 329 | 11.985428 | 0.7948376 | 4693 | 170.96539 | 6.474147 | 188 | 6.8488160 | 0.3687522 | 800 | 29.143898 | 0.7356124 | 1864 | 67.90528 | 2.5860022 | 650 | 23.679417 | 1.6359754 |
| 2019 | 1 | 62 | 10.147300 | 0.4466793 | 5 | 0.8183306 | 0.0901645 | 70 | 11.456629 | 0.7377195 | 102 | 16.693944 | 0.4453258 | 164 | 26.84124 | 2.0252425 | 20 | 3.273322 | 0.2603445 | 286 | 46.80851 | 3.092065 | 6 | 0.9819967 | 0.0986888 | 33 | 5.400982 | 0.2535572 | 140 | 22.91326 | 1.2930593 | 34 | 5.564648 | 0.4325070 |
| 2020 | 0 | 774 | 29.609793 | 0.8402477 | 50 | 1.9127774 | 0.1370003 | 1154 | 44.146901 | 0.9813697 | 909 | 34.774292 | 3.4473183 | 2518 | 96.32747 | 17.2944212 | 209 | 7.995409 | 0.6187186 | 3848 | 147.20735 | 3.759894 | 123 | 4.7054323 | 0.2529673 | 601 | 22.991584 | 0.6057577 | 1869 | 71.49962 | 1.6170580 | 401 | 15.340474 | 0.6853909 |
| 2020 | 1 | 37 | 7.789474 | 0.3186135 | 2 | 0.4210526 | 0.0648201 | 73 | 15.368421 | 0.8391540 | 115 | 24.210526 | 0.5794619 | 118 | 24.84211 | 1.5238514 | 8 | 1.684211 | 0.1288153 | 159 | 33.47368 | 1.032976 | 12 | 2.5263158 | 0.1570888 | 24 | 5.052632 | 0.2377255 | 131 | 27.57895 | 1.2055354 | 49 | 10.315789 | 1.0633373 |
| 2021 | 0 | 675 | 25.911708 | 0.7559533 | 76 | 2.9174664 | 0.1750386 | 1097 | 42.111324 | 0.9940373 | 770 | 29.558541 | 1.6351552 | 2138 | 82.07294 | 11.3631455 | 144 | 5.527831 | 0.2629444 | 3917 | 150.36468 | 4.288430 | 143 | 5.4894434 | 0.2927373 | 734 | 28.176583 | 0.6970378 | 1724 | 66.18042 | 1.5890188 | 282 | 10.825336 | 0.5085568 |
| 2021 | 1 | 34 | 8.114558 | 0.3289866 | 2 | 0.4773270 | 0.0690062 | 70 | 16.706444 | 0.8969719 | 108 | 25.775656 | 0.6637617 | 129 | 30.78759 | 1.7093075 | 9 | 2.147971 | 0.1882092 | 195 | 46.53938 | 1.447856 | 4 | 0.9546539 | 0.0973551 | 24 | 5.727924 | 0.2326532 | 131 | 31.26492 | 1.1820457 | 15 | 3.579952 | 0.2516121 |
#define custom color scale
myColors <- brewer.pal(4, "Spectral")
names(myColors) <- levels(sheriff_crime_grouped$`Presence of Gangs`)
custom_colors <- scale_colour_manual(name = "Presence of Gangs", values = myColors)
#visualization
sheriff_crime_grouped %>% ggplot(aes(x = year, y = mean_robbery, color = `Presence of Gangs`)) +
geom_line() + theme(legend.title = element_text(size=8)) +
ylab("") +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Robbery (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Homicide (x100)") + theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Burglary (x100)") + theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Weapon Crimes (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Assault (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Sexual Crimes (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Theft (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_grouped %>% ggplot(aes(x = year, y = mean_reckless_driving, color = `Presence of Gangs`)) +
geom_line() + theme_minimal() + theme(legend.title = element_text(size=8)) +
ylab("") + scale_x_continuous(breaks=seq(2005,2021,2)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Reckless Driving (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Fraud (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Vandalism (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))
sheriff_crime_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)) +
custom_colors + theme_ipsum() + ggtitle("LA Sheriff - Average Cases of Alcohol Offenses (x100)") +
theme(plot.title = element_text(size = 10, face = "bold"), axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=1, size = 10))