The interactive counterpart of map_pair(): both quantities on one map, with
a control to switch between them.
Usage
leaflet_pair(
x,
value,
uncertainty,
uncertainty_from = NULL,
by = NULL,
coords = NULL,
crs = NULL,
kind = c("surface", "probability"),
uncertainty_kind = c("surface", "diverging"),
uncertainty_midpoint = 0,
uncertainty_direction = 1,
labels = NULL,
transform = "auto",
limits = NULL,
probs = c(0, 0.99),
popup = NULL,
tiles = "Esri.WorldGrayCanvas",
opacity = 0.8,
position = "topright"
)Arguments
- x
The geometry, or a
map_data. Both panels are drawn from it unlessuncertainty_fromnames a different object.- value
What the left panel colours by.
- uncertainty
What the right panel colours by: a CV, a standard error, a posterior standard deviation, an extrapolation score.
- uncertainty_from
A second object to take
uncertaintyfrom, when it does not live alongsidevalue. Must cover the same cells.- by, coords, crs
Passed to
as_map_data().crsis also the CRS the map is drawn in – seedisplay_crs()for what happens when it is not given.- kind
How the left panel is scaled:
"surface"for a skewed positive quantity,"probability"for one bounded at 0 and 1.- uncertainty_kind
How the right panel is scaled.
"surface"for a CV or an SE, which only increase;"diverging"for a signed score such as an extrapolation surface, which needsuncertainty_midpoint.- uncertainty_midpoint
The centre for a diverging right panel. Zero is the usual meaning and it is the default here, unlike in
map_diverging(), because the caller has already said the panel is diverging.- uncertainty_direction
Which way the diverging ramp runs on the right panel.
-1puts the warm arm at the low end, which is what an extrapolation surface wants.- labels
A length-2 character vector naming the two quantities. These are what the switch is labelled with, so they should read as names rather than as units.
- transform, limits, probs
Passed to
surface_scale(), so the colours match the static map's exactly.- popup
Extra columns of
xto show when a cell is clicked, as a character vector. The value and the join key are always shown.FALSEturns popups off.- tiles
A leaflet provider name for the basemap, or
NULLfor no basemap at all. The default is"Esri.WorldGrayCanvas", a quiet grey one, so the data is the brightest thing on the map rather than competing with a road network. It is also key-free: see the note onleaflet_base().- opacity
How opaque the cells are over the basemap.
- position
Where the layer control sits.
Why one map and a switch, rather than two maps side by side
map_pair() draws two panels because a static figure has no other way to
show two things at once, and it goes to some trouble – shared extent, shared
projection, one coastline, aligned panels – to make them comparable cell by
cell. All of that is machinery for approximating, on paper, something an
interactive map gets for free.
Switching layers on one map is a blink comparison: the same cells, at the
same position and the same zoom, changing only in the quantity drawn. Nothing
has to be aligned because nothing moved. Two side-by-side widgets would
reintroduce exactly the alignment problem map_pair() exists to solve, and
would need a synchronisation dependency to solve it again.
The trade is that the two can no longer be seen simultaneously. When that is
what you want – a figure for a manuscript, or a reader who cannot click –
map_pair() is the one to use.
Each layer carries its own legend, shown and hidden with it, because the two are different quantities in different units.
See also
map_pair(), the static original.
Examples
if (FALSE) { # \dontrun{
grid <- example_grid()
leaflet_pair(grid, "density", "cv")
leaflet_pair(grid, "density", "mess", uncertainty_kind = "diverging",
uncertainty_direction = -1,
labels = c("density", "extrapolation"))
} # }