Street Crime UK – Shiny App
This article is originally published at https://r-video-tutorial.blogspot.com/
Introduction
Usage
dateInput
tool), then a crime type and click Draw Map
to update the map with new data. I also included a option to plot the Ripley K-function (function Kest
in package spatstat
) and the p-value of the quadrat.test
(again from spatstat
). Both tools work using the data shown within the screen area, so their results change as users interact with the map. The Ripley K function shows a red dashed line with the expected nearest neighbour distribution of points that are randomly distributed in space (i.e. follow a Poisson distribution). The black line is the one computed from the points shown on screen. If the black line is above the red means the observations shown on the map are clustered, while if it is below the red line means the crimes are scattered regularly in space. A more complete overview of the Ripley K function is available at this link from ESRI.NOTE
rdrop2
, which requires a token to download data from Dropbox. More info github.com/karthik/rdrop2.url
that points to my Dropbox will clearly not be shared.Preparing the dataset
lista = list.files("E:/CrimesUK",pattern="street",recursive=T,include.dirs=T,full.names=T,ignore.case = T)
for(i in lista){
DF = read.csv(i)
write.table(data.frame(LAT=DF$Latitude, LON=DF$Longitude, TYPE=DF$Crime.type),
file=paste0("E:/CrimesUK/CrimesUK",substr(paste(DF$Month[1]),1,4),"_",substr(paste(DF$Month[1]),6,7),".csv"),
sep=",",row.names=F,col.names=F, append=T)
print(i)
}
for
loop to iterate through the files. The loop simply loads each file and than save part of its contents (namely coordinates and crime type) into new csv named after using year and month. This will help me identify which files to download from Dropbox, based on user inputs.fveronesi.shinyapps.io/CrimeUK/
Thanks for visiting r-craft.org
This article is originally published at https://r-video-tutorial.blogspot.com/
Please visit source website for post related comments.