Learn R Programming

mapboxer: An R Interface to Mapbox GL JS

Mapboxer makes Mapbox GL JS, an open source JavaScript library that uses WebGL to render interactive maps, available within R via the htmlwidgets package.

Installation

Install the release version from CRAN with:

install.packages("mapboxer")

Install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("crazycapivara/mapboxer")

Usage

library(mapboxer)

map <- motor_vehicle_collisions_nyc %>%
  dplyr::mutate(
    color = ifelse(injured == 0, "yellow", "red")
  ) %>%
  as_mapbox_source() %>%
  mapboxer(
    center = c(-73.9165, 40.7114),
    zoom = 10
  ) %>%
  add_navigation_control() %>%
  add_circle_layer(
    circle_color = c("get", "color"),
    circle_blur = 1,
    circle_stroke_color = "red",
    circle_stroke_width = 1,
    popup = "<p>{{date}} {{time}}</p><p>Number of persons injured: {{injured}}</p>"
  )

if (interactive()) map

By default mapboxer uses Carto vector styles as basemaps. It is also possible to use raster tiles or a background color.

If you want to use styles from Mapbox it is recommended that you store your API token in an environment vatiable called MAPBOX_API_TOKEN.

Documentation

Development

All JavaScript code of mapboxer is located in javascript/src.

Install dependencies and build the library with:

npm install
npm run build

The module is written to inst/htmlwidgets.

Spin up the dev server with:

npm run start

Copy Link

Version

Install

install.packages('mapboxer')

Monthly Downloads

343

Version

0.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Stefan Kuethe

Last Published

November 4th, 2020

Functions in mapboxer (0.4.0)

add_filter_control

Add a filter control to the map
add_draw_control

Add a draw control to the map (experimental)
add_circle_layer

Add a circle layer to the map
add_control

Add a standard control to the map
add_text_control

Add a text control to the map
add_source

Add a Mapbox source to the map
mapbox_source

Create a Mapbox source
mapboxer-shiny

Shiny bindings for mapboxer
set_layer_properties

Update layer properties
set_style

Set the style of the map
add_mouse_position_control

Add a mouse position control to the map
add_layer

Add a layer to the map
mapboxer

Create a mapboxer widget
mapboxer_proxy

Create a mapboxer proxy object
add_fill_layer

Add a fill layer to the map
add_marker

Add a single marker to the map
add_line_layer

Add a line layer to the map
basemaps

A list of basemap style URLs
fit_bounds

Fit the map to a bounding box
add_popups

Add popups to a layer
as_mapbox_source

Convert a data object to a Mapbox GeoJSON source
add_tooltips

Add tooltips to a layer
motor_vehicle_collisions_nyc

Motor Vehicle Collisions in NYC
reexports

Objects exported from other packages
basemap_background_style

Create a background style
update_mapboxer

Update a mapboxer proxy object in a Shiny app
basemap_raster_style

Create a raster style
set_view_state

Set the view state of the map
stamen_raster_tiles

Get Stamen raster tile URLs
set_data

Update the data of a Mapbox source
set_filter

Set the filter of a layer