The Scatterplot Layer takes in coordinate points and renders them as circles with a certain radius.

add_scatterplot(
  map,
  data = get_map_data(map),
  lon = NULL,
  lat = NULL,
  polyline = NULL,
  radius = NULL,
  radius_min_pixels = 1,
  radius_max_pixels = NULL,
  fill_colour = NULL,
  fill_opacity = NULL,
  stroke_colour = NULL,
  stroke_width = NULL,
  stroke_opacity = NULL,
  tooltip = NULL,
  auto_highlight = FALSE,
  highlight_colour = "#AAFFFFFF",
  layer_id = NULL,
  id = NULL,
  palette = "viridis",
  na_colour = "#808080FF",
  legend = FALSE,
  legend_options = NULL,
  legend_format = NULL,
  digits = 6,
  update_view = TRUE,
  focus_layer = FALSE,
  transitions = NULL,
  brush_radius = NULL
)

Arguments

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 data containing the polylines, if using encoded polylines

radius

in metres. Default 1

radius_min_pixels

the minimum radius in pixels. Can prevent circle from getting too small when zoomed out small for the given zoom level

radius_max_pixels

the maximum radius in pixels. Can prevent the circle from getting too big when zoomed in

fill_colour

column of data or hex colour for the fill colour. If using a hex colour, use either a single value, or a column of hex colours on data

fill_opacity

Either a string specifying the column of data containing the opacity of each shape, or a single value in [0,255], or [0, 1), to be applied to all the shapes. Default 255. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string

stroke_colour

variable of data or hex colour for the stroke. If used, elevation is ignored. If using a hex colour, use either a single value, or a column of hex colours on data

stroke_width

width of the stroke in meters. If used, elevation is ignored. Default 1.

stroke_opacity

Either a string specifying the column of data containing the opacity of each shape, or a single value in [0,255], or [0, 1), to be applied to all the shapes. Default 255. If a hex-string is used as the colour, this argument is ignored and you should include the alpha on the hex string

tooltip

variable of data containing text or HTML to render as a tooltip

auto_highlight

logical indicating if the shape under the mouse should auto-highlight

highlight_colour

hex string colour to use for highlighting. Must contain the alpha component.

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

id

an id value in data to identify layers when interacting in Shiny apps.

palette

string or matrix. String will be one of colourvalues::colour_palettes(). A matrix must have at least 5 rows, and 3 or 4 columns of values between [0, 255], where the 4th column represents the alpha. You can use a named list to specify a different palette for different colour options (where available), e.g. list(fill_colour = "viridis", stroke_colour = "inferno")

na_colour

hex string colour to use for NA values

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.

legend_format

A list containing functions to apply to legend values. See section legend

digits

number of digits for rounding coordinates

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

transitions

list specifying the duration of transitions.

brush_radius

radius of the brush in metres. Default NULL. If supplied, the arcs will only show if the origin or destination are within the radius of the mouse. If NULL, all arcs are displayed

Details

add_scatterplot supports POINT and MULTIPOINT sf objects

transitions

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 scatterplot

list( position = 0, fill_colour = 0, radius = 0 )

data

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

legend

The legend_options can be used to control the appearance of the legend. This should be a named list, where the names are one of

  • css - a string of valid css for controlling the appearance of the legend

  • title - a string to use for the title of the legend

  • digits - number to round the legend values to

If the layer allows different fill and stroke colours, you can use different options for each. See examples in add_arc.

The legend_format can be used to control the format of the values in the legend. This should be a named list, where the names are one of

  • fill_colour

  • stroke_colour

depending on which type of colouring the layer supports.

The list elements must be functions to apply to the values in the legend.

id

The id is returned to your R session from an interactive shiny environment by observing layer clicks. This is useful for returning the data.frame row relating to the cliked shape.

From within a shiny server you would typically use observeEvent({input$map_arc_click}), where 'map' is the map_id supplied to mapdeckOutput(), and 'arc' is the layer you are clicking on

Examples

# \donttest{ ## You need a valid access token from Mapbox key <- 'abc' set_token( key ) mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>% add_scatterplot( data = capitals , lat = "lat" , lon = "lon" , radius = 100000 , fill_colour = "country" , layer_id = "scatter_layer" , tooltip = "capital" )
#> default
## using legend options mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>% add_scatterplot( data = capitals , lat = "lat" , lon = "lon" , radius = 100000 , fill_colour = "lon" , stroke_colour = "lat" , layer_id = "scatter_layer" , tooltip = "capital" , legend = T , legend_options = list( digits = 5 ) )
#> default #> default
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), ] mapdeck(style = mapdeck_style("dark"), pitch = 45 ) %>% add_scatterplot( data = df , lat = "lat" , lon = "lng" , layer_id = "scatter_layer" , stroke_colour = "lng" )
#> default #> default
## as an sf object library(sfheaders) sf <- sfheaders::sf_point( df, x = "lng", y = "lat") mapdeck( style = mapdeck_style("dark"), pitch = 45 ) %>% add_scatterplot( data = sf , radius = 100 , fill_colour = "country" , layer_id = "scatter_layer" , tooltip = "capital" )
#> default
# }