Learn R Programming

simplevis (version 4.5.0)

leaflet_sf_col: Simple feature leaflet map that is coloured.

Description

Map of simple features in leaflet that is coloured.

Usage

leaflet_sf_col(
  data,
  col_var,
  label_var = NULL,
  popup_vars_vctr = NULL,
  pal = NULL,
  pal_na = "#7F7F7FFF",
  pal_rev = FALSE,
  size_point = 2,
  size_line = 2,
  alpha = 0.9,
  basemap = "light",
  title = NULL,
  col_cuts = NULL,
  col_labels = NULL,
  col_method = NULL,
  col_na = TRUE,
  col_pretty_n = 4,
  col_right_closed = TRUE,
  map_id = "map"
)

Arguments

data

An sf object of geometry type point/multipoint, linestring/multilinestring or polygon/multipolygon geometry type. Required input.

col_var

Unquoted variable to colour the features by. Required input.

label_var

Unquoted variable to label the features by. If NULL, defaults to using the colour variable.

popup_vars_vctr

Vector of quoted variable names to include in the popup. If NULL, defaults to making a leafpop::popupTable of all columns.

pal

Character vector of hex codes.

pal_na

The hex code or name of the NA colour to be used.

pal_rev

Reverses the palette. Defaults to FALSE.

size_point

Size of points (i.e. radius). Defaults to 2.

size_line

Size of lines around features (i.e. weight). Defaults to 2.

alpha

The opacity of the fill within features (i.e. fillOpacity). Defaults to 0.1.

basemap

The underlying basemap. Either "light", "dark", "satellite", "street", or "ocean". Defaults to "light". Only applicable where shiny equals FALSE.

title

A title string that will be wrapped into the legend.

col_cuts

A vector of cuts to colour a numeric variable. If "bin" is selected, the first number in the vector should be either -Inf or 0, and the final number Inf. If "quantile" is selected, the first number in the vector should be 0 and the final number should be 1. Defaults to quartiles.

col_labels

A vector to modify colour scale labels.

col_method

The method of colouring features, either "bin", "quantile" or "category." If numeric, defaults to "bin".

col_na

TRUE or FALSE of whether to include col_var NA values. Defaults to TRUE.

col_pretty_n

For a numeric colour variable of "bin" col_method, the desired number of intervals on the colour scale, as calculated by the pretty algorithm. Defaults to 4.

col_right_closed

For a numeric colour variable, TRUE or FALSE of whether bins or quantiles are to be cut right-closed. Defaults to TRUE.

map_id

The shiny map id for a leaflet map within a shiny app. For standard single-map apps, id "map" should be used. For dual-map apps, "map1" and "map2" should be used. Defaults to "map".

Value

A leaflet object.

Examples

Run this code
# NOT RUN {
leaflet_sf_col(example_sf_point, 
               col_var = trend_category)

leaflet_sf_col(example_sf_polygon, 
               col_var = density, 
               col_method = "quantile", 
               col_cuts = c(0, 0.25, 0.5, 0.75, 0.95, 1))

leaflet_sf_col(example_sf_polygon, 
               col_var = density, 
               col_method = "bin", 
               col_cuts = c(0, 10, 50, 100, 150, 200, Inf))

# }

Run the code above in your browser using DataLab