{"id":13735690,"url":"https://github.com/crazycapivara/r2deck","last_synced_at":"2026-05-20T04:42:41.722Z","repository":{"id":44045949,"uuid":"220791852","full_name":"crazycapivara/r2deck","owner":"crazycapivara","description":"An R Interface to deck.gl and Mapbox GL Visualizations","archived":false,"fork":false,"pushed_at":"2023-01-07T11:35:30.000Z","size":1107,"stargazers_count":1,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T14:15:40.674Z","etag":null,"topics":["deck-gl","htmlwidgets","mapbox-gl","maps","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crazycapivara.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-10T13:10:06.000Z","updated_at":"2020-01-12T19:56:12.000Z","dependencies_parsed_at":"2023-02-07T01:31:18.434Z","dependency_job_id":null,"html_url":"https://github.com/crazycapivara/r2deck","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazycapivara%2Fr2deck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazycapivara%2Fr2deck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazycapivara%2Fr2deck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crazycapivara%2Fr2deck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crazycapivara","download_url":"https://codeload.github.com/crazycapivara/r2deck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244637098,"owners_count":20485446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deck-gl","htmlwidgets","mapbox-gl","maps","r"],"created_at":"2024-08-03T03:01:09.797Z","updated_at":"2026-05-20T04:42:41.674Z","avatar_url":"https://github.com/crazycapivara.png","language":"R","funding_links":[],"categories":["R","Visualization"],"sub_categories":["Maps and Spatial Data"],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n# _r2deck_ - An R Interface to deck.gl and Mapbox GL Visualizations\n\n[![Travis build status](https://travis-ci.org/crazycapivara/r2deck.svg?branch=master)](https://travis-ci.org/crazycapivara/r2deck)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![CRAN status](https://www.r-pkg.org/badges/version/r2deck)](https://cran.r-project.org/package=r2deck)\n\nThe _r2deck_ package makes it possible to visualize your R data in [deck.gl](https://deck.gl/) and\n[Mapbox GL](https://github.com/mapbox/mapbox-gl-js). It was inspired by the [r2d3](https://rstudio.github.io/r2d3/) package. In contrast to other existing packages, it is a low-level interface giving you a high degree of flexibility regarding the customization of your visualization.\n\n## Installation\n\nYou can install the latest version of _r2deck_ from [GiHub](https://github.com) with:\n\n``` r\nremotes::install_github(\"crazycapivara/r2deck\")\n```\n\n## Getting Started\n\nTo visualize your data you have to create a JavaScript file containing your visualization function called `r2deckViz`. The JavaScript visualization function takes 3 parameters:\n\n* `map` - The map object on which the layers will be rendered, either of type `deck.DeckGL` or `mapboxgl.Map`.\nThis object is automatically created.\n* `data` - The data that is passed from R to the vizualisation function.\n* `options` - Additional options that can be passed from R to the vizualisation function.\n\nFurthermore, the libraries/variables `deck` and `mapboxgl` are available through the global context.\n\nThe JavaScript file is then passed to the `r2deck` or `r2mapbox` function in R together with the data and parameters to style the map object.\n\nSo let's take a look at a basic example.\n\nFirst fetch some flight data:\n\n```{r data}\ndata_url \u003c- paste0(\n  \"https://raw.githubusercontent.com/plotly/datasets/master/\",\n  \"2011_february_aa_flight_paths.csv\"\n)\nflights \u003c- data.table::fread(data_url)\nhead(flights)\n```\n\nThen create your visualization function to render an arc layer like this:\n\n``` javascript\n// arc.js\nfunction r2deckViz(map, data, options) {\n  // Create an arc layer\n  const arcLayer = new deck.ArcLayer({\n    id: \"arc-layer\",\n    data: data,\n    getSourcePosition: data =\u003e [data.start_lon, data.start_lat],\n    getTargetPosition: data =\u003e [data.end_lon, data.end_lat],\n    getSourceColor: data =\u003e [64, 255, 0],\n    getTargetColor: data =\u003e [0, 128, 200]\n  });\n\n  // Add the layer to the map\n  map.setProps({\n    layers: [ arcLayer ]\n  });\n}\n```\n\nFinally, send the data to your visualization function:\n\n``` r\nlibrary(r2deck)\n\nr2deck(\n  script = \"arc.js\",\n  data = flights,\n  # viewport parameters that are passed to the deck/map object\n  lng = -87.6500523,\n  lat = 41.850033,\n  zoom = 2,\n  pitch = 45\n)\n\n```\n\nFor further examples take a look at the [example scripts](inst/examples) of the package.\n\n## Mapbox Access Token\n\nIn order to use mapbox styles you need to put your access token in  an environment variable called `MAPBOX_ACCESS_TOKEN`. If not set globally, you can run:\n\n``` r\nSys.setenv(MAPBOX_ACCESS_TOKEN = \"your-token\")\n```\n\n## _sf_ data objects\n\nIt is straight forward to pass [sf](https://github.com/r-spatial/sf) data objects to your visualization function. Just tell the data accessor to get the geometries from the _geometry_ column:\n\n``` javascript\nconst polygonLayer = new PolygonLayer({\n  id: \"nc\",\n  data: data,\n  getPolygon: data =\u003e data.geometry,\n  // ...\n}\n```\n\nSee also the [polygon layer example](inst/examples/polygon-layer.R).\n\n## Documentation\n\nThe documentation is still work in progress as this package is in an early state.\n\nAs a good starting point check the [deck.gl api documentation](https://deck.gl/#/documentation/deckgl-api-reference/) where you have a lot of examples on how your JavaScript visualization function should look like.\n\nBasically you just need to define one or more layers using your data object that is passed via `r2deck` to your function and then add it to the map:\n\n``` javascript\nfunction r2deckViz(map, data, options) {\n  const gridLayer = new deck.GridLayer({\n    id: \"grid-layer\",\n    data: data,\n    // ...\n  });\n  \n  map.setProps({\n    layers: [ gridLayer ]\n  });\n}\n\n// Columns from your data are accessed like this:\ndata.column_name\n\n// If you have the columns 'lat' and 'lng' in your data.frame\n// a data accessor would be:\ngetPosition: data =\u003e [data.lng, data.lat]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazycapivara%2Fr2deck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrazycapivara%2Fr2deck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrazycapivara%2Fr2deck/lists"}