rbokeh
packageThe package and the Python library website. Bokeh graphing library runs in different languages (Python, Scala, Julia, R). We can plot all kinds of charts and some maps: the gallery.
With the mtcars
dataset.
library(rbokeh)
<- lm(dist ~ speed, data = cars)
z
<- figure(width = 600, height = 600) %>%
p ly_points(cars, hover = cars) %>%
ly_lines(lowess(cars), legend = "lowess") %>%
ly_abline(z, type = 2, legend = "lm")
p
hexbin
plotsThis is a dataset about 753 working women. 428 work outside the home, 325 don’t. We remove observations where hours
is zero. We also have socioeconomic factors affecting the work decision.
<- figure(width = 600, height = 600) %>%
p ly_points(faminc, hours, data = work, color = largecity, glyph = largecity,
hover = list(faminc, hours, taxableinc, hfathereduc, hmothereduc, kids618, age))
p
figure(width = 600, height = 600) %>%
ly_hexbin(faminc, hours, data = work)
rbokeh
can work with map databases such as maps
, mapdata
(and mapproj
). The only interactions are with the ‘events’ displayed on the map (points, bubbles, choropleth (fill)). However, for a fully interactive package: leaflet
.
library(maps)
data(world.cities)
<- subset(world.cities, capital == 1)
caps $population <- prettyNum(caps$pop, big.mark = ",")
caps
figure(width = 800, height = 450, padding_factor = 0) %>%
ly_map("world", col = "gray") %>%
ly_points(long, lat, data = caps, size = 5, hover = c(name, country.etc, population))
CMA: Census Metropolitan Area.
From "world", "Canada"
.
library(maps)
library(mapdata)
data(canada.cities)
<- subset(canada.cities, pop >= 1000000)
metro $population <- prettyNum(metro$pop, big.mark = ",")
metro
figure(width = 800, height = 450, padding_factor = 0) %>%
ly_map("world", "Canada", col = "lightgray") %>%
ly_points(long, lat, data = metro, size = 10, color = 'red',
hover = c(name, country.etc, population))
From "worldHires", "Canada"
.
library(maps)
library(mapdata)
figure(width = 800, height = 450, padding_factor = 0) %>%
ly_map("worldHires", "Canada", col = "lightgray") %>%
ly_points(long, lat, data = metro, size = 10, color = 'red',
hover = c(name, country.etc, population))
the ly_polygons
function can hangle spatial vectors, but again, rbokeh
should not be the first choice for plotting maps.
The distribution of the Joshua Tree (hover of the points to see the pollinator).
= read.csv('data/JoTrPresence02202008_dryad.csv')
bkgd
gmap(lat = 35.75, lng = -116.25, zoom = 6, width = 700, height = 600) %>%
ly_points(longitude, latitude, data = bkgd, alpha = 0.8, col = "red", hover = c(pollinator, longitude, latitude))
Nothing about OpenStreetMaps.