For this project, I sought to demonstrate how just changing the
mathematical method for choosing the “cut points” in the distrubition of
attributes can vastly change how a chloropleth map can look. The method
can be found at the top left of each map above the legend.
All credit for the instructions and data go to Crime Mapping and Spatial Data Analysis using R by Juanjo Medina and Reka Solymosi.
Code can be found below.
library(readr)
library(dplyr)
library(janitor)
library(skimr)
library(sf)
library(tmap)
library(tmaptools)
library(DCluster)
library(geodaData)
manchester = st_read("https://raw.githubusercontent.com/maczokni/crime_mapping/master/data/manchester.geojson", quiet = TRUE)
manchester <- mutate(manchester,
crimr1 = (count/respop)*100000, # crime per residential population
crimr2 = (count/wkdpop)*100000) # crime per workday population
current_style <- tmap_style("cobalt")
tm_shape(manchester) +
tm_fill("crimr1", title = "Crime per 100,000 residents") +
tm_borders(alpha = 0.1)
tm_layout(main.title = "Crime in Manchester City, Nov/2017",
main.title.size = 0.7 ,
legend.outside = TRUE, # Place legend outside of map
legend.title.size = 0.8)
## $tm_layout
## $tm_layout$legend.outside
## [1] TRUE
##
## $tm_layout$legend.title.size
## [1] 0.8
##
## $tm_layout$main.title
## [1] "Crime in Manchester City, Nov/2017"
##
## $tm_layout$main.title.size
## [1] 0.7
##
## $tm_layout$style
## [1] NA
##
##
## attr(,"class")
## [1] "tm"
map1 <- tm_shape(manchester) +
#Use tm_fill to specify variable, classification method,
# and give the map a title
tm_fill("crimr1", style="equal", title = "Equal") +
tm_layout(legend.position = c("left", "top"),
legend.title.size = 0.7, legend.text.size = 0.5)
map2 <- tm_shape(manchester) +
tm_fill("crimr1", style="jenks", title = "Jenks") +
tm_layout(legend.position = c("left", "top"),
legend.title.size = 0.7, legend.text.size = 0.5)
map3 <- tm_shape(manchester) +
tm_fill("crimr1", style="quantile", title = "Quantile") +
tm_layout(legend.position = c("left", "top"),
legend.title.size = 0.7, legend.text.size = 0.5)
map4 <- tm_shape(manchester) +
tm_fill("crimr1", style="sd", title = "Standard Deviation") +
tm_layout(legend.position = c("left", "top"),
legend.title.size = 0.7, legend.text.size = 0.5)
map5 <- tm_shape(manchester) +
tm_fill("crimr1", style="headtails", title = "Headtails") +
tm_layout(legend.position = c("left", "top"),
legend.title.size = 0.7, legend.text.size = 0.5)
tmap_arrange(map1, map2, map3, map4, map5)