addContour | R Documentation |
Convenience function to add contourlines to a map, specifically geared towards suggesting boundaries to the result of weightedMap. Internally based on a krige-interpolation.
addContour(heights, points, window, crs, add = TRUE, polygons = FALSE,
levels = c(0.4, 0.45, 0.5), grid = 50000, ...)
heights |
Numeric vector with the same length as |
points |
Locations of the datapoints as |
window |
Window for the interpolation as |
crs |
A crs in WKT format. |
add |
By default, contourlines are added to the previous plot. Otherwise, they are returns as |
polygons |
Should polygons be returned instead of linestrings? Only applicable when |
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 |
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 |
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
.
Contourlines are added to the current plot or (when add=FALSE
) they are returned as an sf object with a sfc_LINESTRING
geometry.
This is a preliminary convenience function that will be used to overhaul levelMap
Michael Cysouw <cysouw@mac.com>
weightedMap
for more involved example
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(sf::st_geometry(p), col = cols[as.character(heights)], pch = 19)
plot(sf::st_geometry(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, 0.55), col = "blue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.