Learn R Programming

googleway (version 2.7.1)

add_heatmap: Add heatmap

Description

Adds a heatmap to a google map

Usage

add_heatmap(map, data = get_map_data(map), lat = NULL, lon = NULL,
  weight = NULL, option_gradient = NULL, option_dissipating = FALSE,
  option_radius = 0.01, option_opacity = 0.6, layer_id = NULL,
  update_map_view = TRUE, digits = 4, legend = F, legend_options = NULL)

Arguments

map

a googleway map object created from google_map()

data

data frame containing the data to use in the layer. If Null, the data passed into google_map() will be used.

lat

string specifying the column of data containing the 'latitude' coordinates. If left NULL, a best-guess will be made

lon

string specifying the column of data containing the 'longitude' coordinates. If left NULL, a best-guess will be made

weight

string specifying the column of data containing the 'weight' associated with each point. If NULL, each point will get a weight of 1.

option_gradient

vector of colours to use as the gradient colours. see Details

option_dissipating

logical Specifies whether heatmaps dissipate on zoom. When dissipating is FALSE the radius of influence increases with zoom level to ensure that the color intensity is preserved at any given geographic location. When set to TRUE you will likely need a greater option_radius value. Defaults to FALSE.

option_radius

numeric. The radius of influence for each data point, in pixels. Defaults to 0.01

option_opacity

The opacity of the heatmap, expressed as a number between 0 and 1. Defaults to 0.6.

layer_id

single value specifying an id for the layer. Use this value to distinguish between shape layers for when using any update_ function, and for separating legends.

update_map_view

logical specifying if the map should re-centre according to the shapes

digits

integer. Use this parameter to specify how many digits (decimal places) should be used for the latitude / longitude coordinates.

legend

either a logical indiciating if the legend(s) should be displayed, or a named list indicating which colour attributes should be included in the legend.

legend_options

A list of options for controlling the legend.

Details

The legend will only show if you supply a weight variable.

option_gradient colours can be two of the R colour specifications; either a colour name (as listed by colors(), or a hexadecimal string of the form "#rrggbb").

The first colour in the vector will be used as the colour that fades to transparent, and is not actually mapped to any data points (and therefore won't be included in the legend). The last colour in the vector will be use in the centre of the 'heat'.

The option_gradient, option_dissipating, option_radius and option_opacity values apply to all points in the data.8

Examples

Run this code
# NOT RUN {
map_key <- 'your_api_key'

set.seed(20170417)
df <- tram_route
df$weight <- sample(1:10, size = nrow(df), replace = T)

google_map(key = map_key, data = df) %>%
 add_heatmap(lat = "shape_pt_lat", lon = "shape_pt_lon", weight = "weight",
              option_radius = 0.001, legend = T)

## specifying different colour gradient
option_gradient <- c('orange', 'blue', 'mediumpurple4', 'snow4', 'thistle1')

google_map(key = map_key, data = df) %>%
 add_heatmap(lat = "shape_pt_lat", lon = "shape_pt_lon", weight = "weight",
              option_radius = 0.001, option_gradient = option_gradient, legend = T)

 
# }

Run the code above in your browser using DataLab