Description Usage Arguments Details note transitions data Examples
View source: R/map_layer_heatmap.R
The Heatmap Layer can be used to visualise spatial distribution of data. It implements Gaussian Kernel Density Estimation to render the heatmaps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
map |
a mapdeck map object |
data |
data to be used in the layer. All coordinates are expected to be EPSG:4326 (WGS 84) coordinate system |
lon |
column containing longitude values |
lat |
column containing latitude values |
polyline |
optional column of |
weight |
the weight of each value. Default 1 |
colour_range |
vector of 6 hex colours |
radius_pixels |
Radius of the circle in pixels, to which the weight of an object is distributed |
intensity |
Value that is multiplied with the total weight at a pixel to obtain the final weight. A value larger than 1 biases the output color towards the higher end of the spectrum, and a value less than 1 biases the output color towards the lower end of the spectrum |
threshold |
The HeatmapLayer reduces the opacity of the pixels with relatively low weight to create a fading effect at the edge. A larger threshold smoothens the boundaries of color blobs, while making pixels with low relative weight harder to spot (due to low alpha value). Threshold is defined as the ratio of the fading weight to the max weight, between 0 and 1. For example, 0.1 affects all pixels with weight under 10% of the max. |
layer_id |
single value specifying an id for the layer. Use this value to distinguish between shape layers of the same type. Layers with the same id are likely to conflict and not plot correctly |
update_view |
logical indicating if the map should update the bounds to include this layer |
focus_layer |
logical indicating if the map should update the bounds to only include this layer |
digits |
number of digits for rounding coordinates |
transitions |
list specifying the duration of transitions. |
add_heatmap
supports POINT and MULTIPOINT sf objects
The current version of this layer is supported only for WebGL2 enabled browswers So you may find it doesn't render in the RStudio viewer.
The transitions argument lets you specify the time it will take for the shapes to transition from one state to the next. Only works in an interactive environment (Shiny) and on WebGL-2 supported browsers and hardware.
The time is in milliseconds
Available transitions for heatmap
list( intensity = 0, threshold = 0, radius_pixels = 0 )
If the data
is a simple feature object, the geometry column is automatically
detected. If the sf object contains more than one geometry column and you want to use a specific one,
you'll need to set the active geometry using sf::st_geometry( x ) <- "your_column"
,
where "your_column"
is the name of the column you're activating. See ?sf::st_geometry
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## You need a valid access token from Mapbox
key <- 'abc'
set_token( key )
df <- read.csv(paste0(
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/',
'examples/3d-heatmap/heatmap-data.csv'
))
df <- df[ !is.na(df$lng), ]
df$weight <- sample(1:10, size = nrow(df), replace = TRUE)
mapdeck( style = mapdeck_style('dark'), pitch = 45 ) %>%
add_heatmap(
data = df
, lat = "lat"
, lon = "lng"
, weight = "weight",
, layer_id = "heatmap_layer"
)
## as an sf object
library(sfheaders)
sf <- sfheaders::sf_point( df, x = "lng", y = "lat")
mapdeck( style = mapdeck_style('dark'), pitch = 45 ) %>%
add_heatmap(
data = sf
, weight = "weight",
, layer_id = "heatmap_layer"
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.