This article has moved to Posit Connect Cloud.

  1. Data Loading
  2. Data preparation (please contact me for the proprocessing)
    1. Formatting the Year
    2. Crime type allocation
  3. Data mining
    1. Year-wise crime counts
    2. Gender-wise crime counts
    3. Race-wise crime counts

1. Data Loading

Arrests<- read_csv("data/Arrests.csv")  ## Uncleaned data
## Rows: 13777 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): ArrestDatetime, Statute, StatuteDescription, Street, Race, Sex
## dbl (2): ArrestID, HouseNumber
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

2. Data Preparation

(hidden; please ask me if you need this part of code)

2b. Formatting Date

2b. Crime-type allocation

3. Data mining

3a. Year-wise crime counts

ggplot(data=Arrests,aes(x=Year,fill=CrimeType))+ 
  geom_bar(position='stack') + theme_classic() +
  scale_fill_manual(values = c("steelblue", "cadetblue",
                               "darkseagreen","bisque","coral","coral3")) +
   
  xlab("Year") + ylab("Crimes Count")+
  ggtitle("Charlottesville Crime Report (2017 - 2021)")+ 
  theme(plot.title = element_text(hjust = 0.5,size=32))+
  theme(axis.text.x=element_text(size=18),
        axis.title.x =element_text(size=18),
        axis.text.y = element_text(size=18),
        axis.title.y= element_text(size=18),
        legend.text = element_text(size=12),
        legend.title = element_text(size=16))

3b. Gender-wise crime counts

# Cleaning the Gender variable
remove=  which(Arrests$Sex=="Unknown" | is.na(Arrests$Sex)) 
Arrests_Gender<- Arrests[-remove,]  
ggplot(data=Arrests_Gender,aes(x=Year,fill=CrimeType))+ 
  geom_bar(position='stack') + theme_classic() +
  scale_fill_manual(values = c("steelblue", "cadetblue",
                               "darkseagreen","bisque","coral","coral3")) +
   
  xlab("Year") + ylab("Crimes Count")+
  ggtitle("Charlottesville Crime Report (2017 - 2021)")+ 
  theme(plot.title = element_text(hjust = 0.5,size=32))+
  theme(axis.text.x=element_text(size=20),
        axis.title.x =element_text(size=20),
        axis.text.y = element_text(size=20),
        axis.title.y= element_text(size=20),
        legend.text = element_text(size=15),
        legend.title = element_text(size=20),
        strip.text = element_text(size = 20))+
  facet_wrap(~Sex,)

3c. Race-wise crime counts

# Cleaning the Gender variable
remove= c(which(is.na(Arrests$Race)),which(Arrests$Race=="doc"),which( Arrests$Race=="nwt"), which( Arrests$Race=="jpg"),which( Arrests$Race=="Unknown"))
Arrests_Race<-Arrests[-remove,]
ggplot(data=Arrests_Race,aes(x=Year,fill=CrimeType))+ 
  geom_bar(position='stack') + theme_classic() +
  scale_fill_manual(values = c("steelblue", "cadetblue",
                               "darkseagreen","bisque","coral","coral3")) +
   
  xlab("Year") + ylab("Crimes Count")+
  ggtitle("Charlottesville Crime Report (2017 - 2021)")+ 
  theme(plot.title = element_text(hjust = 0.5,size=32))+
  theme(axis.text.x=element_text(size=20),
        axis.title.x =element_text(size=20),
        axis.text.y = element_text(size=20),
        axis.title.y= element_text(size=20),
        legend.text = element_text(size=15),
        legend.title = element_text(size=20),
        strip.text = element_text(size = 20))+
  facet_wrap(~Race,scales = "free_y")