Learn R Programming

tmap (version 1.2)

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

shp
shape object, which is one of
  1. SpatialPolygons(DataFrame)

Value

  • Shape object with appended data.

item

  • data
  • key.shp
  • key.data
  • ignore.duplicates
  • ignore.na
  • fixed.order

code

shp

Examples

Run this code
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")

Run the code above in your browser using DataLab