points_layer: Points layer

Description Usage Arguments Examples

View source: R/points_layer.R

Description

Add a points layer to a d3-carto-map.

Usage

1
2
3
4
points_layer(carto, data, x = "long", y = "lat", label = "Points",
  color = "red", size = 4, radius_field = NULL, clickable = TRUE,
  visible = TRUE, cluster = FALSE, opacity = 0.5,
  radius_func = "d3.scale.sqrt().domain([0, layer.radius_domain]).range([0, layer.size])")

Arguments

carto

The map created by cartographer().

data

A data frame with columns for the latitude and longitude in decimal degrees. It may also contain other columns to be used as properties.

x

The name of the column in the data frame with the longitudes.

y

The name of the column in the data frame with the latitudes.

label

The label for this layer on the layer selector.

color

The color of the points, either as a name recognized by a browser or as a hexadecimal string (e.g., #4527f3).

size

The radius of the points. If the parameter radius_field is set so that the points are scaled to a variable in data, then the size parameter controls the maximum size of the points.

radius_field

The name of a numeric field in the data frame passed to data. This field will be used to scale the points. The domain of the scale will run from 0 to the maximum value in the radius_field; the range will run from 0 to the value in size.

clickable

Controls whether a point can be clicked to show the properties in the data frame.

visible

Should the layer be initially visible?

cluster

If true, when the map is zoomed points will be clustered on a quadtree. If the points are clustered, arguments that control the size of points will be disregarded.

opacity

The opacity of points on the map: a number between 0 and 1.

radius_func

A D3 quantitative scale function to control the radius of the points.

Examples

1
2
3
4
5
6
7
if(require(historydata)) {
  cartographer(region = "United States") %>%
    tile_layer() %>%
    points_layer(data = paulist_missions, x = "long", y = "lat",
                 color = "blue", label = "Missions",
                 radius_field = "confessions", size = 8)
}

ropensci/cartographer documentation built on May 27, 2019, 2:24 p.m.