| mn_join | R Documentation |
Attaches a data frame to boundaries in one step. The column in by can
hold names in any common spelling, Cyrillic names, NSO codes, ISO codes
or P-codes; they are matched with mn_match(). Every unit of the level
is kept, so places without data still appear on the map (with NA).
mn_join(
data,
by,
level = NULL,
by_parent = NULL,
within = NULL,
drop_other_levels = TRUE,
resolution = c("low", "high"),
lang = NULL,
crs = NULL
)
data |
A data frame. |
by |
The column of |
level |
The level of the places in |
by_parent |
Optional column of |
within |
Keep only units inside these places, or these places
themselves: names or codes of any level, such as |
drop_other_levels |
If |
resolution |
|
lang |
Language of the |
crs |
Coordinate reference system of the result. |
Level. When level is NULL, the level with the most matches is
used. NSO tables often list several levels in one column (the national
total, regions, aimags, soums ...); rows at other levels are dropped with
a message (see drop_other_levels). Join NSO tables by their code column
(such as Region) rather than the label column: labels such as
"Ulaanbaatar" name both a region and an aimag.
Several rows per unit. Data with several rows per place (for
example one per year) give several copies of that place's polygon, ready
for ggplot2::facet_wrap().
Places without boundaries. Villages (tosgon) and rural bags have NSO codes but no boundary; their rows are reported and left out.
An sf tibble: the boundaries of every unit at the level, with
the columns of data added. Columns of data whose names clash with
boundary columns get the suffix .data.
Other joining data:
mn_example_population
# Mid-year population from NSO, by aimag and year
pop <- mn_example_population[mn_example_population$Year == 2025, ]
mn_join(pop, by = "Region", level = "aimag")
# Khoroos of Ulaanbaatar, from the same table
mn_join(pop, by = "Region", level = "bag", within = "Ulaanbaatar")
# Names in any spelling work
df <- data.frame(aimag = c("Khovsgol", "Hovd", "\\u0423\\u0432\\u0441"), value = 1:3)
mn_join(df, aimag)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.