Learn R Programming

qlcVisualize (version 0.4)

addContour: Add contourlines to a map

Description

Convenience function to add contourlines to a map, specifically geared towards suggesting boundaries to the result of weightedMap. Internally based on a krige-interpolation.

Usage

addContour(heights, points, window, crs,
           levels = c(0.4, 0.45, 0.5), grid = 50000, ...)

Value

Contourlines are added to the current plot.

Arguments

heights

Numeric vector with the same length as points. Typically a 0/1 vector describing presence or absence of a features.

points

Locations of the datapoints as sfc_POINTS or an sf object with such a geometry.

window

Window for the interpolation as sfc_POLYGON or an sf object with such a geometry.

crs

A crs in WKT format.

levels

Levels on which to draw the contourlines. Multiple lines get thicker towards higher values to suggest a center. These levels have to be related relative to the heights.

grid

Number of points inside the window for the krige-interpolation. Higher numbers lead to nicers contourlines, but take longer to evaluate.

...

Additional specifications passed internally to contour.

Author

Michael Cysouw <cysouw@mac.com>

Details

Internally, a grid is made inside the window and the height is interpolated using ordinary kriging from [gstat]{krige} with a model suggested by autofitVariogram.

See Also

weightedMap for more involved example

Examples

Run this code
data(hessen)

# continuous variable between 0 and 1
data <- hessen$data[,1:3]
heights <- round(data[,1]/rowSums(data), digits = 1)
cols <- heat.colors(11)
names(cols) <- names(table(heights))

# boundary as sf
w <- sf::st_as_sf(hessen$boundary)
sf::st_crs(w) <- 4326
w <- sf::st_transform(w, 2397)

# points as sf
p <- sf::st_as_sf(hessen$villages, coords = c("longitude", "latitude"))
sf::st_crs(p) <- 4326
p <- sf::st_transform(p, 2397)

# plot map
plot(p, col = cols[as.character(heights)], border = NA, pch = 19)
plot(w, add = TRUE, border = "grey")

# add boundary
addContour(heights, points = p, window = w, crs = 2397, grid = 1000,
            levels = c(0.25, 0.35, 0.45), col = "blue")

Run the code above in your browser using DataLab