Display names for the members of a GeoScale. A label belongs to a
region at a geoframe and to a named variant – a free name such as
"name", "short" or a language code – so a region may carry several
names. The table is sparse: a geoframe may label every region, some, or
none, and whatever has no label is shown by its code. A row with
region = NA names the geoframe itself.
Usage
attach_labels_geoscale(
x,
labels,
variant = NULL,
default = NULL,
overwrite = FALSE
)
geoscale_labels(x, geoframe = NULL, variant = NULL)
geoscale_label(x, region, geoframe, variant = NULL)Arguments
- x
A
GeoScale.- labels
A
data.framewith columnsgeoframe,region,labeland optionallyvariant. Thenestedscalesnamesframeandmemberare accepted for the first two.- variant
For
attach_labels_geoscale(): the variant the rows belong to whenlabelshas novariantcolumn (default"label"). For the readers: the variant to return;NULLis every variant ingeoscale_labels()and the default one ingeoscale_label().- default
Name of the variant used when none is asked for.
NULLkeeps the current default (initially the first variant attached).- overwrite
Replace a label already present for the same region and variant.
FALSE(default) makes that an error.- geoframe
The geoframe: for
geoscale_labels()a filter (NULLfor all), forgeoscale_label()the geoframe the codes are at.- region
Character vector of region codes at
geoframe;NAstands for the geoframe itself.
Value
attach_labels_geoscale() the GeoScale;
geoscale_labels() a data.frame with columns geoframe, region,
variant, label; geoscale_label() a character vector as long as
region.
Details
attach_labels_geoscale() adds rows (and may set the default variant),
geoscale_labels() returns the table, and geoscale_label() looks names
up for a vector of codes, returning the code where there is no label.
Subsetting and pruning keep the labels of what remains, and the plots use
the default variant.
Examples
gs <- attach_labels_geoscale(
geoscale_example(),
data.frame(geoframe = "country", region = c("N", "S"),
label = c("Northland", "Southland")),
variant = "name"
)
gs <- attach_labels_geoscale(
gs,
data.frame(geoframe = "country", region = "N", label = "Nordland"),
variant = "de"
)
geoscale_labels(gs)
#> geoframe region variant label
#> 1 country N name Northland
#> 2 country S name Southland
#> 3 country N de Nordland
geoscale_label(gs, c("N", "S"), "country")
#> [1] "Northland" "Southland"
geoscale_label(gs, c("N", "S"), "country", variant = "de")
#> [1] "Nordland" "S"
geoscale_label(gs, c("N1", "ZB"), "zone") # no labels: the codes
#> [1] "N1" "ZB"
