Introducing 'CrimeMap'

Using R, Shiny and ShinyApps for Quick Web App Development

Jo-fai Chow (University of Exeter & XP Solutions)
Final Year EngD Candidate in Hydroinformatics (Water + Machine Learning)


  1. Why R?
  2. Introducing 'CrimeMap'
  3. What's Next?
  4. Beyond Data and Maps
  5. Conclusions
  6. Q & A

Above: Hadley Wickham's LondonR talk on dplyr and ggvis back in July 2013 (my first ever LondonR experience).

Why R ?

What People Think I Do


What People Think I Do


R Can Do That ?


... and more !?

Thanks to Tal Galili's


Taking My Leap of Faith (Jan - Mar 2013)

Data Analysis (Coursera)

  • MOOC by Jeff Leek

  • Practical data analysis using R

  • Peer reviewed assignments

  • Kaggle Competition

The 'R' Awesomeness

  • Data Manipulation (reshape2, plyr)
  • Machine Learning (caret)
  • Parallel Processing (foreach, doSNOW)
  • Big Data (bigmemory, ff, RHadoop)
  • Visualisation (rCharts, ggplot2, animation)
  • Dynamic Documentation (knitr, roxygen2)
  • User Community (LondonR)
  • Active Development of New Packages (ggvis, dplyr, SparkR ...)

Introducing 'CrimeMap'

CrimeMap - The Original by David Kahle



CrimeMap - Maybe I can try it with different data?

Is there any?


Open Data and API!

Download crime data within a 1 mile radius of a single point (JSON)

Raw Data in JSON format

{"category" : "anti-social-behaviour", 
 "month"    : "2012-04", 
 "location" : {
  "latitude"  : "52.640374", 
  "longitude" : "-1.122319",
  "street"    : {
   "id"   : 884330, 
   "name" : "On or near Christow Street"}}, 
  ... and some other stuff}

Improvement since then

Specific area (JSON) and batch download (CSV).

Putting it together!

First Milestone: A Wrapper Function (June 2013)

crimeplot.wrapper <- function(

    ## user-defined location
    point.of.interest = "London Eye", 

    ## period of time in YYYY-MM
    period = c("2013-01","2013-02",

    ## terrain, satellite, hybrid          = "roadmap",

    ## month, category, type
    type.facet        = NA



CrimeMap - Application Examples (Map Type)


Brighton (Map: Hybrid)


Bristol (Map: Terrain)

CrimeMap - Application Examples (Facet)


Sheffield (by Category)


Exeter (by Month)

Making it Shiny!

CrimeMap - Making it Shiny!


"Shiny makes it super simple for R users like you to turn analyses into interactive web applications that anyone can use." - RStudio

ShinyApps Server

"ShinyApps is a platform as a service (PaaS) for hosting Shiny applications ... allowing you to create your online account, and deploy your first Shiny application to the cloud." - RStudio


"It looks fun! Maybe I can learn a new trick!"


"Can I make it super user-friendly ... so easy that even my mom knows how to use it?"

"Is it really possible? I have NO prior web app development experience at all."

"Will it work on mobile devices?"

Second Milestone: Shiny Web App (Nov 2013)

CrimeMap - Keep It Simple, Stupid

Basic Controls


Push the Button!



CrimeMap - Control Freak !!!

More Controls

What's Your Favourite?

Sharing it with the world!

CrimeMap - Hosting it with ShinyApps

Set Credentials

setAccountInfo(name   = "blenditbayes", 
               token  = "your_token", 
               secret = "your_secret") 

Deploy it!

deployApp(appDir  = "your_app_dir",
          appName = "your_app_name")

Configure Instance Type

configureApp(appName = "crimemap", 
             size    = "xlarge") 

Available Options

Instance Memory Size
small (default) 256 MB
medium 512 MB
large 1024 MB
xlarge 2048 MB
xxlarge 4096 MB

For More Information

  1. ShinyApps (Hassle-free Cloud Hosting) Link
  2. Shiny Server (Host Your Own) - Free and Professional Version Link

CrimeMap - Using it on iPhone 4s & Nexus 7



CrimeMap - Forked Projects

Summary of Experience

CrimeMap - Summary of My Shiny Experience

Developing with Shiny

  1. Rapid development - from noob to my first web app in a few days!
  2. Default layout is nice and simple. You can further customise it with CSS.
  3. It works on mobile devices!
  4. Easy code sharing.
  5. Even my mom knows how to use it!!!

Hosting with ShinyApps

  1. Hassle-free. No need to worry about maintenance and data usage.
  2. Deploy (or update) your app in minutes.
  3. Great support from the RStudio team!

What's Next?

Discovering Cool Stuff from Ramnath Vaidyanathan

You've probably seen ...

... and now 'rMaps' !

What if ... rMaps + CrimeMap?

Introducing Package 'rCrimemap'


install.packages(c("ggmap", "rjson",

Latest RStudio IDE (v0.98.501+)

Install 'rCrimemap'


Function 'rcmap()'

  location = "Ball Brothers EC3R 7PP", 
  period = "2014-01",
  type = "All",
  map_size = c(1000, 500), 
  provider = "Nokia.normalDay",
  zoom = 10)


Introducing Package 'rCrimemap' - LondonR Demo

require(rCrimemap); rcmap("Ball Brothers EC3R 7PP");

# [rCrimemap]: Downloading '2010-12.rda' from author's Bitbucket account ...
# [rCrimemap]: Converting raw data into JSON format for Leaflet ...
# [rCrimemap]: Creating Leaflet with Heat Map ...

# [rCrimemap]: =======================================================
# [rCrimemap]: Summary of Crime Data Used and Leaflet Map
# [rCrimemap]: =======================================================

# Point of Interest           : Ball Brothers EC3R 7PP 
# Police Force(s)             : Metropolitan Police Service City of London Police 
# Period of Crime Records     : 2010-12 
# Type of Crime Records       : All 
# Total No. of Crime Records  : 93077 
# Map Resolution              : 1000 x 500 

Introducing Package 'rCrimemap' - LondonR Demo

rcmap("Ball Brothers EC3R 7PP", 
      "2011-08", "All", c(1000,1000),

      "2014-01", "All", c(1000,1000), 

Beyond Data Points and Fancy Graphs

Related BBC Articles

Beyond Exploratory Analysis

  • Can we trust the data?
  • Can we improve the data?
  • Can we learn from the data?
  • Can we predict crime rate?
  • Can we optimise the resources?
  • Can we build a new decision support system?



  • Reasons why I shifted to R
    • R is excellent for data mining, visualisation, big data, dynamic doc etc.
  • CrimeMap
    • a wonderful learning experience.
    • a case study for Shiny and ShinyApps.
  • Things keep evolving
    • rMaps + CrimeMap = rCrimemap

Want to Find Out More About Shiny?

John M. Chambers on R

"R has had a revolutionary effect on the way statistics are communicated ..."

"... for many things now, people produce the code, they produce an R package, an instantly, everyone else can use what they've got freely and contribute their ideas to let things evolve."



Thanks For

Coursera & Jeff Leek

Data Analysis Online Course

David Kahle & Hadley Wickham

ggmap and ggplot2

Open Crime Data and API

RStudio Team (esp. Tareef Kawaf)

RStudio IDE, Shiny & ShinyApps

Chris Beeley & Packt

For the Shiny Cookbook

Ramnath Vaidyanathan

Slidify, rCharts and rMaps

... and, most importantly, of course ...

Mango Solutions

... kindly sponsoring and supporting

LondonR since 2009!

Thank You for Your Attention!