O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

The RgoogleMaps package offers tremendous ease of use but does not allow you control over the map elements and the type of layout. So we will look at another R package, ggmap, powered by the popular ggplot2 package, to overlay data points over the map. In this section, we will analyze the Chicago crime dataset downloaded from https://data.cityofchicago.org/ and simplified for this example:

  1. Install and load ggmap and maps and read the data, chicago-crime.csv:
> install.packages(c("ggmap","maps"))> library(maps)> library(ggmap)> crimes <- read.csv("chicago-crime.csv")
  1. Format the Date column into Date object:
> crimes$Date = strptime(crimes$Date, format = "%m/%d/%y %H:%M")
  1. Get the map of Chicago using the get_map function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required