https://github.com/crazycapivara/mapboxer
An R Interface to Mapbox GL JS
https://github.com/crazycapivara/mapboxer
htmlwidgets mapbox-gl-js r spatial webgl
Last synced: 2 months ago
JSON representation
An R Interface to Mapbox GL JS
- Host: GitHub
- URL: https://github.com/crazycapivara/mapboxer
- Owner: crazycapivara
- License: other
- Created: 2020-06-18T08:14:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-04T22:17:16.000Z (over 1 year ago)
- Last Synced: 2025-04-15T21:41:57.979Z (3 months ago)
- Topics: htmlwidgets, mapbox-gl-js, r, spatial, webgl
- Language: R
- Homepage: https://crazycapivara.github.io/mapboxer/
- Size: 2.48 MB
- Stars: 55
- Watchers: 1
- Forks: 7
- Open Issues: 59
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mapboxer: An R Interface to Mapbox GL JS[](https://CRAN.R-project.org/package=mapboxer)
[](https://github.com/crazycapivara/mapboxer/releases/latest)
[](https://travis-ci.org/crazycapivara/mapboxer)
[](https://www.repostatus.org/#active)`mapboxer` makes [Mapbox GL JS](https://docs.mapbox.com/mapbox-gl-js/api/),
an open source JavaScript library that uses WebGL to render interactive maps,
available within R via the [htmlwidgets](https://www.htmlwidgets.org/) package.
## Note
`mapboxer` provides bindings to v1.x.x of Mapbox GL JS, which is under the 3-Clause BSD license. See also [breaking changes in Mapbox GL JS v2.0.0](https://github.com/mapbox/mapbox-gl-js/releases/tag/v2.0.0).
## Installation
Install the release version from [CRAN](https://cran.r-project.org/) with:
```r
install.packages("mapboxer")
```Install the development version from [GitHub](https://github.com/) with:
```r
# install.packages("remotes")
remotes::install_github("crazycapivara/mapboxer")
```## Usage
```{r examples}
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 = "{{date}} {{time}}
Number of persons injured: {{injured}}
"
)if (interactive()) map
```By default mapboxer uses [Carto vector styles](https://github.com/CartoDB/basemap-styles)
as basemaps. It is also possible to use raster tiles or a background color.If you want to use styles from [Mapbox](https://www.mapbox.com/maps) it is recommended that you store your API token in an environment vatiable called `MAPBOX_API_TOKEN`.
## Documentation
- [Get Started](https://crazycapivara.github.io/mapboxer/articles/mapboxer.html)
- [API Reference](https://crazycapivara.github.io/mapboxer/reference/)
- [Examples](https://github.com/crazycapivara/mapboxer/tree/master/examples)
- [Showcase](https://crazycapivara.github.io/mapboxer/articles/examples/showcase.html)## Development
All JavaScript code of mapboxer is located in `javascript/src`.
Install dependencies and build the library with:
```bash
npm install
npm run build
```The module is written to `inst/htmlwidgets`.
Spin up the dev server with:
```bash
npm run start
```