This post was originally published by Ryan Hafen on his website, RyanHafen.com, and has been reprinted here with his permission.

There are many map plotting features in rBokeh that I haven’t been able to cover in detail in the documentation. This post will go into a few of those, including google map types, custom map styles, and using different layer functions to plot on top of a map.

Bokeh has the ability to use a Google map as a backdrop for plotting. For example, here’s a map of Manhattan and surrounding area:

# install.packages("rbokeh", repos = "http://packages.tessera.io")
library(rbokeh)

gmap(lat = 40.73306, lng = -73.97351, zoom = 12,
  width = 680, height = 600)

This is what you typically expect to get with a Google map - you can pan and zoom (click the mouse zoom tool in the toolbar to zoom), etc. To get a map we simply call gmap() and specify the latitude and longitude of the center of the area we want to see and the level of zoom, ranging from 1 (world) to 20 (buildings).

For the sake of having an example to use in this post, I downloaded the December 2015 NYC Citi Bike data from here and summarized the number of times a bike was picked up or dropped off at each of the stations. This summary is stored in a github gist here.

Let’s start by reading it in.

bike - read.csv("https://gist.githubusercontent.com/hafen/3d534ee95b964ef753ab/raw/dbe9f0cbe29d17151d852e8cc1c3466f7a7f02e9/201512_nycbike_summ.csv", stringsAsFactors = FALSE)

head(bike)
#           station      lat       lon n_start n_end
# 1 1 Ave & E 15 St 40.73222 -73.98166    4258  4272
# 2 1 Ave & E 18 St 40.73381 -73.98054    2854  2860
# 3 1 Ave & E 30 St 40.74144 -73.97536    3241  3251
# 4 1 Ave & E 44 St 40.75002 -73.96905    2020  2013
# 5 1 Ave & E 62 St 40.76123 -73.96094    2165  2156
# 6 1 Ave & E 68 St 40.76501 -73.95818    3533  3530