20/1/2017

I started by examining the crimes.RData package using the head function

crimes %>% head(n=4)
## # A tibble: 4 × 10
##                date  hour offense   beat premise block_range     street
##              <fctr> <chr>  <fctr> <fctr>  <fctr>      <fctr>     <fctr>
## 1 01/08/10 00:00:00    22  Murder  11H30     20R   3000-3099   BROADWAY
## 2 01/17/10 00:00:00    18  Murder  10H50     18C   2800-2899    MCGOWEN
## 3 01/01/10 00:00:00     0  Murder  15E30     18A   9600-9699    MARLIVE
## 4 01/09/10 00:00:00    14  Murder   5F20     13R   9000-9099 LONG POINT
## # ... with 3 more variables: type <fctr>, suffix <fctr>, n_events <chr>

Code for creating a basic overview of the crime data

crimes %>%  ggplot(aes(x=offense)) + geom_bar() -> cplot 
cplot + labs(x='Offense Type',y="Number of Offenses (1000's)") + 
  scale_y_continuous(breaks=c(0,100000,200000,300000),
  labels=c(0,100,200,300)) + theme_economist() -> cplot 

Basic plot of Crimes Data

cplot

Graph of Crimes by Day of the Week

R Code for creating graphs using the package ggplot2 & the Economist theme

crimes %>%  ggplot(aes(x=hour(date))) + geom_bar()  + 
  labs(x='Time of Day',y="Number of Offenses") + 
  scale_x_continuous(breaks=c(3,9,12,15,21),
  labels=c("3am","9am","Noon","3pm","9pm")) -> crime_time
crime_time + theme_economist() -> crime_time

Graph of Crimes by Time of Day

crime_time

Graph of Aggravated Assaults by Day of the Week

Code for creating Graph of Murders by time of day

murders %>% ggplot(aes(x=hour(date))) + geom_bar() + labs(y='Number of Murders',x='Time of Day') + 
  scale_x_continuous(breaks=c(3,9,15,21),labels=c("3am","9am","3pm","9pm")) -> murder_time
murder_time + theme_economist() -> murder_time

Graph of Murder by Time of Day

murder_time

Tmap code for creating maps

read_shape('./counties/counties.shp') -> cty 
cty %>% qtm

If I want to make the map interactive

tmap_mode('view')
## tmap mode set to interactive viewing
cty %>% qtm

Here is an interactive map I made using the murder data from Houston, TX

## Joining, by = "addr"

Here is a more precise map using coloured coding

I have hidden the code due to amount of warnings created