Description Usage Arguments Details Value Examples
Data, in the format of a data.frame, is appended to a shape object. This is either done by a left join where keys are specified for both shape and data, or by fixed order. Under coverage (shape items that do not correspond to data records), over coverage (data records that do not correspond to shape items respectively) as well as the existence of duplicated key values are automatically checked and reported via console messages. With under_coverage
and over_coverage
the under and over coverage key values from the last append_data
call can be retrieved. Tip: run append_data
without assigning the result to check the coverage. Note that this function supports sf
objects, but still uses sp-based methods (see details).
1 2 3 4 5 6 7 | append_data(shp, data, key.shp = NULL, key.data = NULL,
ignore.duplicates = FALSE, ignore.na = FALSE,
fixed.order = is.null(key.data) && is.null(key.shp))
under_coverage()
over_coverage()
|
shp |
shape object, which is one of
|
data |
data.frame |
key.shp |
variable name of |
key.data |
variable name of |
ignore.duplicates |
should duplicated keys in |
ignore.na |
should NA values in |
fixed.order |
should the data be append in the same order as the shapes in |
This function supports sf
objects, but still uses sp-based methods, from the packages sp, rgeos, and/or rgdal. Alternatively, the tidyverse
method left_join
can be used.
Shape object with appended data. Tip: run append_data
without assigning the result to check the coverage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## Not run:
if (require(tmap)) {
data(World)
f <- tempfile()
download.file("http://kejser.org/wp-content/uploads/2014/06/Country.csv", destfile = f)
domain_codes <- read.table(f, header=TRUE, sep="|")
unlink(f)
domain_codes <- subset(domain_codes, select = c("Alpha3Code", "TopLevelDomain"))
domain_codes$Alpha3Code <- toupper(domain_codes$Alpha3Code)
World <- append_data(World, domain_codes, key.shp = "iso_a3", key.data = "Alpha3Code",
ignore.na = TRUE)
# codes in the data, but not in Europe:
oc <- over_coverage()
oc$value
# Countries without appended data:
uc <- under_coverage()
current_mode <- tmap_mode("view")
qtm(World[uc$id,], text="name")
# plot the result
qtm(World, text="TopLevelDomain")
tmap_mode(current_mode)
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.