In view mode, the interactive map has a layer control box in the corner.
Each layer can be assigned to a named group
Users can toggle groups on and off using check boxes or radio buttons
Basemaps are always radio buttons (only one at a time)
Data layers default to check boxes
This is set via the group and group.control arguments in layer functions.
The group argument
tmap_mode("view")tm_shape(NLD_dist) +tm_polygons(fill ="dwelling_value",col =NULL,fill.legend =tm_legend("Dwelling value (×1000)"),group ="District data") +# ← group nametm_shape(NLD_muni) +tm_borders(lwd =1, group ="Municipality borders") +tm_shape(NLD_prov) +tm_borders(lwd =3) # ← group name inherited from tm_shape()
If group is not specified, the group name is inherited from the shape name in tm_shape().
group.control options
Value
Behaviour
"check"
Check box — layer can be shown/hidden independently (default)
"radio"
Radio button — only one layer in the radio group shown at a time
"none"
Layer is always visible; not shown in the control box
Switching between layers with radio buttons
Useful when the same variable is available at different spatial resolutions. group.control = "none" on the basemap keeps it out of the radio group:
tmap_mode("view")tm_shape(NLD_dist) +tm_polygons(fill ="dwelling_value", col =NULL,fill.legend =tm_legend("Dwelling value (×1000)"),group ="District level", group.control ="radio") +tm_shape(NLD_muni) +tm_polygons(fill ="dwelling_value", col =NULL,fill.legend =tm_legend("Dwelling value (×1000)"),group ="Municipality level", group.control ="radio") +tm_shape(NLD_prov) +tm_borders(lwd =3, group.control ="none") +tm_basemap("OpenStreetMap", group.control ="none")
Layer draw order
The plotting order of layers is determined by the zindex argument (or call order when not specified) — not by the group.