The Heatmap Layer can be used to visualise spatial distribution of data. It implements Gaussian Kernel Density Estimation to render the heatmaps.

  data = get_map_data(map),
  lon = NULL,
  lat = NULL,
  polyline = NULL,
  weight = NULL,
  colour_range = NULL,
  radius_pixels = 30,
  intensity = 1,
  threshold = 0.05,
  layer_id = NULL,
  update_view = TRUE,
  focus_layer = FALSE,
  digits = 6,
  transitions = NULL



a mapdeck map object


data to be used in the layer. All coordinates are expected to be EPSG:4326 (WGS 84) coordinate system


column containing longitude values


column containing latitude values


optional column of data containing the polylines, if using encoded polylines


the weight of each value. Default 1


vector of 6 hex colours


Radius of the circle in pixels, to which the weight of an object is distributed


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


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.


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


logical indicating if the map should update the bounds to include this layer


logical indicating if the map should update the bounds to only include this layer


number of digits for rounding coordinates


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


# \donttest{ ## You need a valid access token from Mapbox key <- 'abc' set_token( key ) df <- read.csv(paste0( '', 'examples/3d-heatmap/heatmap-data.csv' )) df <- df[ !$lng), ] df$weight <- sample(1:10, size = nrow(df), replace = T) mapdeck( style = mapdeck_style('dark'), pitch = 45 ) %>% add_heatmap( data = df , lat = "lat" , lon = "lng" , weight = "weight", , layer_id = "heatmap_layer" )
#> Error in google_dispatch(map, method, google_map = { x = map$x$calls if (is.null(x)) x = list() n = length(x) x[[n + 1]] = list(functions = method, args = args) map$x$calls = x map}, google_map_update = { invoke_remote(map, method, args)}): Invalid map parameter
## 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" )
#> Error in find_lat_column(dataNames, layer_call, TRUE): Couldn't infer latitude column for add_heatmap
# }