The following data was downloaded from https://catalog.data.gov/dataset/crimes-2001-to-present-398a4. This dataset contains every crime that was committed in the city of Chicago from 2001 to the present. It contains the location of the crime, the type of crime, the date it was reported, and other descriptive information.
crime<-read.csv("C:/Users/ianh1/Downloads/Crimes2001topresent.csv")
str(crime)
## 'data.frame': 6753677 obs. of 22 variables:
## $ ID : int 10000092 10000094 10000095 10000096 10000097 10000098 10000099 10000100 10000101 10000104 ...
## $ Case.Number : Factor w/ 6753272 levels "",".JB299184",..: 5757556 5757692 5757686 5757688 5757632 5757677 5757684 5757644 5757669 5757625 ...
## $ Date : Factor w/ 2702731 levels "01/01/2001 01:00:00 AM",..: 538445 538538 538530 538520 538478 538510 538538 538497 538512 538490 ...
## $ Block : Factor w/ 59915 levels "0000X E 100 PL",..: 36753 47516 34786 38952 36667 37660 49045 33643 29883 55887 ...
## $ IUCR : Factor w/ 401 levels "0110","0141",..: 31 360 53 41 19 41 53 53 258 41 ...
## $ Primary.Type : Factor w/ 35 levels "ARSON","ASSAULT",..: 3 26 3 3 31 3 3 3 19 3 ...
## $ Description : Factor w/ 379 levels "$300 AND UNDER",..: 41 258 138 316 54 316 138 138 274 316 ...
## $ Location.Description: Factor w/ 180 levels "","ABANDONED BUILDING",..: 159 159 19 19 155 19 19 19 159 141 ...
## $ Arrest : Factor w/ 2 levels "false","true": 1 2 1 1 1 1 1 1 2 1 ...
## $ Domestic : Factor w/ 2 levels "false","true": 1 1 2 1 1 1 2 2 1 1 ...
## $ Beat : int 1111 725 222 225 1113 223 733 213 912 511 ...
## $ District : int 11 7 2 2 11 2 7 2 9 5 ...
## $ Ward : int 28 15 4 3 28 4 17 3 11 6 ...
## $ Community.Area : int 25 67 39 40 25 39 68 38 59 49 ...
## $ FBI.Code : Factor w/ 26 levels "01A","01B","02",..: 6 26 11 11 4 11 11 11 21 11 ...
## $ X.Coordinate : int 1144606 1166468 1185075 1178033 1144920 1183018 1170859 1178746 1164279 1179637 ...
## $ Y.Coordinate : int 1903566 1860715 1875622 1870804 1898709 1872537 1858210 1876914 1880656 1840444 ...
## $ Year : int 2015 2015 2015 2015 2015 2015 2015 2015 2015 2015 ...
## $ Updated.On : Factor w/ 2471 levels "01/01/2007 07:32:02 AM",..: 233 233 233 233 233 233 233 233 233 233 ...
## $ Latitude : num 41.9 41.8 41.8 41.8 41.9 ...
## $ Longitude : num -87.7 -87.7 -87.6 -87.6 -87.7 ...
## $ Location : Factor w/ 860499 levels "","(36.619446395, -91.686565684)",..: 528673 232195 357606 325048 482419 337080 210407 364570 379567 79045 ...
Due to the incredibly large number of observations (6,753,677), a subset of the data will be taken to only show crimes commited it 2017.
crime2017<-crime[crime$Year==2017,]
Now that the data set is more managable, the location and type of crimes will be plotted using the leaflet package to give an idea of where the crimes are being reported. ##Map
library(leaflet)
mymap <- crime2017 %>%
leaflet() %>%
addTiles() %>%
addMarkers(popup=crime2017$Primary.Type , clusterOptions = markerClusterOptions())
mymap