Source: general data set from SANDAG AGENCY, San Diego county**

  1. From https://data.sandiegodata.org/dataset/sandag-gov-crime-2007e2013/
    San Diego county crime incidents,

  2. From SANDAG http://www.sandag.org/programs/public_safety/arjis/CrimeData/crimedata.zip
    sdcrime_16_20.csv

larceny: the unlawful taking of personal property with intent to deprive the rightful owner of it permanently

Cautions:

all <- read.csv("D:/Dataset_main/sd_crime_data.csv")


all %>% filter(year==2018) %>% group_by(CrimeCategory) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))
## # A tibble: 12 x 2
##    CrimeCategory      Total
##    <chr>              <int>
##  1 Simple Assault     43242
##  2 Larceny < $400     27250
##  3 Larceny >= $400    22654
##  4 Vehicle Theft      14706
##  5 Aggravated Assault 14691
##  6 Res Burglary        8278
##  7 Non Res Burglary    5176
##  8 Strong ArmRobbery   4791
##  9 Armed Robbery       3070
## 10 Rape                1501
## 11 Arson                466
## 12 Murder               211
all %>% filter(year==2019) %>% group_by(CrimeCategory) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))
## # A tibble: 13 x 2
##    CrimeCategory      Total
##    <chr>              <int>
##  1 Simple Assault     44707
##  2 Larceny < $400     27050
##  3 Larceny >= $400    23669
##  4 Aggravated Assault 15472
##  5 Vehicle Theft      14731
##  6 Res Burglary        7664
##  7 Non Res Burglary    5731
##  8 Strong ArmRobbery   4360
##  9 Armed Robbery       3330
## 10 Rape                1503
## 11 Arson                380
## 12 Murder               210
## 13 Larceny               18
all %>% filter(year==2020) %>% group_by(CrimeCategory) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))
## # A tibble: 12 x 2
##    CrimeCategory      Total
##    <chr>              <int>
##  1 Simple Assault     23828
##  2 Larceny < $400     13847
##  3 Larceny >= $400    11720
##  4 Aggravated Assault  9228
##  5 Vehicle Theft       8382
##  6 Res Burglary        3799
##  7 Non Res Burglary    3502
##  8 Armed Robbery       1977
##  9 Strong ArmRobbery   1968
## 10 Rape                 623
## 11 Arson                410
## 12 Murder               161
theft<-  all %>%  
    filter(City == "SAN DIEGO") %>%
    filter(CrimeCategory=="Larceny<$400" | CrimeCategory=="Larceny>$400" | 
           CrimeCategory=="Vehicle Theft" | CrimeCategory=="Res Burglary")  


t2017 <- theft %>% filter(year==2017) %>% group_by(chargeDescription) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))

t2018 <- theft %>% filter(year==2018) %>% group_by(chargeDescription) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))

t2019<- theft %>% filter(year==2019) %>% group_by(chargeDescription) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))

t2020 <- theft %>% filter(year==2020) %>% group_by(chargeDescription) %>% summarise(Total=n()) %>%
                           arrange(desc(Total))









head(t2017,n=10) %>%
  kable(caption = "Theft incidences in 2017") %>%
   kable_styling(bootstrap_options = "striped", full_width = F, position = "center") %>%
   column_spec(1:2, color = "black", background = "lightblue") %>%
    footnote(general = "Sub-categories under THEFT")
Theft incidences in 2017
chargeDescription Total
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT 6844
BURGLARY/UNSPECIFIED 2775
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT (F) 741
BURGLARY/FIRST DEGREE 369
ATTEMPTED BURGLARY:DEGREE UNSPECIFIED 195
BURGLARY:UNSPECIFIED 150
BURGLARY/SECOND DEGREE 96
ATTEMPT OPERATE VEHICLE W/O OWNER’S CONSENT 24
ATTEMPT BURGLARY 13
BURGLARY (RESIDENTIAL) (F) 13
Note:
Sub-categories under THEFT
head(t2018,n=10) %>%
  kable(caption = "Theft incidences in 2018") %>%
   kable_styling(bootstrap_options = "striped", full_width = F, position = "center") %>%
   column_spec(1:2, color = "black", background = "lightblue") %>%
    footnote(general = "Sub-categories under THEFT")
Theft incidences in 2018
chargeDescription Total
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT 4052
BURGLARY/UNSPECIFIED 2630
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT (F) 2291
BURGLARY/FIRST DEGREE 389
ATTEMPTED BURGLARY:DEGREE UNSPECIFIED 145
BURGLARY:UNSPECIFIED 133
BURGLARY/SECOND DEGREE 117
BURGLARY (RESIDENTIAL) (F) 48
ATTEMPT BURGLARY 15
ATTEMPT OPERATE VEHICLE W/O OWNER’S CONSENT 15
Note:
Sub-categories under THEFT
head(t2019,n=10) %>%
  kable(caption = "Theft incidences in 2019") %>%
   kable_styling(bootstrap_options = "striped", full_width = F, position = "center") %>%
   column_spec(1:2, color = "black", background = "lightblue") %>%
    footnote(general = "Sub-categories under THEFT")
Theft incidences in 2019
chargeDescription Total
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT (F) 4495
BURGLARY (RESIDENTIAL) (F) 2164
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT 1698
BURGLARY/UNSPECIFIED 887
BURGLARY/FIRST DEGREE 172
OTHER AGENCY VEHICLE THEFT/RECOVERY (F) 101
ATTEMPTED BURGLARY:DEGREE UNSPECIFIED 55
BURGLARY/SECOND DEGREE 46
BURGLARY:UNSPECIFIED 35
BURGLARY (COMMERCIAL) (F) 17
Note:
Sub-categories under THEFT
head(t2020,n=10) %>%
  kable(caption = "Theft incidences in 2020") %>%
   kable_styling(bootstrap_options = "striped", full_width = F, position = "center") %>%
   column_spec(1:2, color = "black", background = "lightblue") %>%
    footnote(general = "Sub-categories under THEFT")
Theft incidences in 2020
chargeDescription Total
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT (F) 3639
BURGLARY (RESIDENTIAL) (F) 1829
OTHER AGENCY VEHICLE THEFT/RECOVERY (F) 204
TAKE VEHICLE W/O OWNER’S CONSENT/VEHICLE THEFT 53
BURGLARY (COMMERCIAL) (F) 39
TAKE VEHICLE WITHOUT OWNER CONSENT WITH SPECIFIC PRIORS (F) 15
GRAND THEFT:MONEY/LABOR/PROPERTY (F) 6
BURGLARY DURING STATE OF EMERGENCY - LOOTING (F) 5
VEH THEFT:SPECIFIC PRS (F) 5
GRAND THEFT (Mot Veh Theft) (F) 4
Note:
Sub-categories under THEFT
theft$activityDate <- ymd_hm(theft$activityDate)


sd <- theft %>% filter(year==2017) %>%
       group_by(chargeDescription) %>%
       summarise(Total=n()) %>%
       arrange(-Total)
head(sd,n=10) %>% ggplot(aes(x = reorder(chargeDescription,Total), y = Total)) +
  geom_bar(stat = "identity", fill = "#756bb1") +
  geom_text(aes(x = chargeDescription, y = Total, label = Total)) +
  labs(x ="Charge Description", y = "Count", title = "2017 Top THEFT Crimes in San Diego city, CA",
       subtitle = " ") + 
  coord_flip()

sd <- theft %>% filter(year==2018) %>%
       group_by(chargeDescription) %>%
       summarise(Total=n()) %>%
       arrange(-Total)
head(sd,n=10) %>% ggplot(aes(x = reorder(chargeDescription,Total), y = Total)) +
  geom_bar(stat = "identity", fill = "#756bb1") +
  geom_text(aes(x = chargeDescription, y = Total, label = Total)) +
  labs(x ="Charge Description", y = "Count", title = "2018 Top THEFT Crimes\nSan Diego city, CA",
       subtitle = " ") + 
  coord_flip()

sd <- theft %>% filter(year==2019) %>%
       group_by(chargeDescription) %>%
       summarise(Total=n()) %>%
       arrange(-Total)
head(sd,n=10) %>% ggplot(aes(x = reorder(chargeDescription,Total), y = Total)) +
  geom_bar(stat = "identity", fill = "#756bb1") +
  geom_text(aes(x = chargeDescription, y = Total, label = Total)) +
  labs(x ="Charge Description", y = "Count", title = "2019 Top THEFT Crimes\nSan Diego city, CA",
       subtitle = " ") + 
  coord_flip()

sd <- theft %>% filter(year==2020) %>%
       group_by(chargeDescription) %>%
       summarise(Total=n()) %>%
       arrange(-Total)
head(sd,n=10) %>% ggplot(aes(x = reorder(chargeDescription,Total), y = Total)) +
  geom_bar(stat = "identity", fill = "#756bb1") +
  geom_text(aes(x = chargeDescription, y = Total, label = Total)) +
  labs(x ="Charge Description", y = "Count", title = "2020 Top THEFT Crimes\nSan Diego city, CA",
       subtitle = " ") + 
  coord_flip()