Learn R Programming

tmap (version 1.4-1)

append_data: Append data to a shape object

Description

Data, in the format of a data.frame, is appended to a shape object. This is either done by a right join where keys are specified for both data and shape, or by fixed order.

Usage

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))

Arguments

data
data.frame
key.shp
variable name of shp map data to be matched with key.data. If not specified, and fixed.order is FALSE, the ID's of the polygons/lines/points are taken.
key.data
variable name of data to be matched with key.shp. If not specified, and fixed.order is FALSE, the row names of data are taken.
ignore.duplicates
should duplicated keys in data be ignored? (FALSE by default)
ignore.na
should NA values in key.data and key.shp be ignored? (FALSE by default)
fixed.order
should the data be append in the same order as the shapes in shp?

Value

Shape object with appended data.

Examples

Run this code
## Not run: 
# data(Europe)
# 
# 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)
# 
# Europe <- append_data(Europe, domain_codes, key.shp = "iso_a3", key.data = "Alpha3Code",
#     ignore.na = TRUE)
# 
# qtm(Europe, text="TopLevelDomain")
# ## End(Not run)

Run the code above in your browser using DataLab