Which countries share a land border with which, as a tidy edge list –
built from polygon topology (sf::st_touches()), so it reflects the same
curated geometry as the rest of the package. Powers neighbors().
Arguments
- scale
Natural Earth resolution to compute adjacency from. This is not a cosmetic choice – see Which countries the default leaves out below.
"large"needs the non-CRANrnaturalearthhirespackage; seeworld_geometry().- region
Optional region subset (see
world_geometry()); a pair is only reported when both countries remain in the subset.
Value
A tibble, one row per bordering pair: iso3c_a, country_a,
iso3c_b, country_b. Each unordered pair appears once, with
iso3c_a <= iso3c_b alphabetically.
Turning it into a graph
igraph::graph_from_data_frame() takes the first two columns as the edge
endpoints, so pass only the two code columns – handing it the whole tibble
would build edges from each country's code to its own name:
Attaching igraph also masks neighbors(), which it exports too, so call
that one as countryatlas::neighbors() from then on.
Which countries the default leaves out
Adjacency is computed from Natural Earth polygons, and the default
scale = "small" (110m) has no polygon at all for the European microstates.
Andorra, Liechtenstein, Monaco, San Marino and the Vatican are therefore
absent from the table entirely – not merely missing a short border, but
contributing no rows, despite a land border being the whole of their
geography. The default reports 310 pairs over 153 countries; France comes
back with 8 neighbours rather than 10.
scale = "medium" (50m) has all five, giving 322 pairs over 162 countries
and France its full list. Use it whenever the microstates matter:
country_borders(scale = "medium")The same 110m gap is why morans_i()'s contiguity weights exclude them –
see its n_excluded – and it is the land-border twin of the island problem
described in vignette("honest-maps"). Note the two Guiana borders are real,
not artefacts: French Guiana makes Brazil and Suriname neighbours of France.
Examples
# \donttest{
if (requireNamespace("sf", quietly = TRUE) &&
requireNamespace("rnaturalearth", quietly = TRUE)) {
head(country_borders(region = "Europe"))
# The whole world is only a little dearer: a fraction of a second.
nrow(country_borders())
}
#> [1] 310
# }
