Skip to contents

Add a heatmap

Adds a heatmap with data from a GeoJSON/TopoJSON file/url

Adds a heatmap with data from a KML file/url

Adds a heatmap with data from a CSV file/url

Adds a heatmap with data from a GPX file/url

removes the heatmap

clears the heatmap

Usage

addHeatmap(
  map,
  lng = NULL,
  lat = NULL,
  intensity = NULL,
  layerId = NULL,
  group = NULL,
  minOpacity = 0.05,
  max = 1,
  radius = 25,
  blur = 15,
  gradient = NULL,
  cellSize = NULL,
  maxZoom = NULL,
  scaleIntensity = TRUE,
  legend = FALSE,
  legendOptions = NULL,
  data = leaflet::getMapData(map)
)

addGeoJSONHeatmap(
  map,
  geojson,
  layerId = NULL,
  group = NULL,
  intensityProperty = NULL,
  minOpacity = 0.05,
  max = 1,
  radius = 25,
  blur = 15,
  gradient = NULL,
  cellSize = NULL
)

addKMLHeatmap(
  map,
  kml,
  layerId = NULL,
  group = NULL,
  intensityProperty = NULL,
  minOpacity = 0.05,
  max = 1,
  radius = 25,
  blur = 15,
  gradient = NULL,
  cellSize = NULL
)

addCSVHeatmap(
  map,
  csv,
  csvParserOptions,
  layerId = NULL,
  group = NULL,
  intensityProperty = NULL,
  minOpacity = 0.05,
  max = 1,
  radius = 25,
  blur = 15,
  gradient = NULL,
  cellSize = NULL
)

addGPXHeatmap(
  map,
  gpx,
  layerId = NULL,
  group = NULL,
  intensityProperty = NULL,
  minOpacity = 0.05,
  max = 1,
  radius = 25,
  blur = 15,
  gradient = NULL,
  cellSize = NULL
)

removeHeatmap(map, layerId)

clearHeatmap(map)

Arguments

map

a map widget object created from leaflet()

lng

a numeric vector of longitudes, or a one-sided formula of the form ~x where x is a variable in data; by default (if not explicitly provided), it will be automatically inferred from data by looking for a column named lng, long, or longitude (case-insensitively)

lat

a vector of latitudes or a formula (similar to the lng argument; the names lat and latitude are used when guessing the latitude column from data)

intensity

intensity of the heat. A vector of numeric values or a formula. Values are interpreted relative to max. If scaleIntensity = TRUE and max is left at the default, values greater than 1 are scaled automatically so that 1 and 500 stay visually distinct.

layerId

the layer id

group

the name of the group the newly created layers should belong to (for clearGroup and addLayersControl purposes). Human-friendly group names are permitted–they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g. markers and polygons) can share the same group name.

minOpacity

minimum opacity at which the heat will start

max

maximum point intensity. The default is 1.0

radius

radius of each "point" of the heatmap. The default is 25.

blur

amount of blur to apply. The default is 15. blur=1 means no blur.

gradient

palette name from RColorBrewer or an array of of colors to be provided to colorNumeric, or a color mapping function returned from colorNumeric

cellSize

the cell size in the grid. Points which are closer than this may be merged. Defaults to `radius / 2`.s Set to `1` to do almost no merging.

maxZoom

zoom level at which a point reaches its full intensity. Leaflet.heat otherwise fades points at low zoom, which makes everything look blue and hides intensity. When scaleIntensity = TRUE and maxZoom is NULL, it defaults to 0 so weights stay visible at world/regional zoom.

scaleIntensity

If TRUE (default) and max was not set by the caller, max becomes the maximum intensity so raw values such as 1 vs 500 are visible. Set to FALSE to keep the previous clipping behavior.

legend

If TRUE, add a color legend for the intensity scale.

legendOptions

A list of arguments passed to addHeatmapLegend, such as title or position.

data

the data object from which the argument values are derived; by default, it is the data object provided to leaflet() initially, but can be overridden

geojson

The geojson or topojson url or contents as string.

intensityProperty

The property to use for determining the intensity at a point. Can be a "string" or a JS function, or NULL.

kml

The KML url or contents as string.

csv

The CSV url or contents as string.

csvParserOptions

options for parsing the CSV. Use csvParserOptions() to supply csv parser options.

gpx

The GPX url or contents as string.

Examples

leaflet(quakes) %>%
  addProviderTiles(providers$CartoDB.DarkMatter) %>%
  setView(178, -20, 5) %>%
  addHeatmap(
    lng = ~long, lat = ~lat, intensity = ~mag,
    blur = 20, radius = 15, legend = TRUE
  )
## for more examples see # browseURL(system.file("examples/heatmaps.R", package = "leaflet.extras")) kml <- readr::read_file( system.file("examples/data/kml/crimes.kml.zip", package = "leaflet.extras") ) leaflet() %>% setView(-77.0369, 38.9072, 12) %>% addProviderTiles(providers$CartoDB.Positron) %>% addKMLHeatmap(kml, radius = 7) %>% addKML( kml, markerType = "circleMarker", stroke = FALSE, fillColor = "black", fillOpacity = 1, markerOptions = markerOptions(radius = 1) )
## for more examples see # browseURL(system.file("examples/KML.R", package = "leaflet.extras"))