## ----vect_1------------------------------------------------------------------- library(terra) p <- vect(system.file("ex/lux.shp", package="terra")) ## ----maps_1, fig.height=5----------------------------------------------------- plot(p) ## ----maps_2, fig.height=5----------------------------------------------------- n <- nrow(p) plot(p, col=rainbow(n)) ## ----maps_3------------------------------------------------------------------- plot(p, "NAME_2", col=rainbow(25)) ## ----maps_4a, fig.width=10---------------------------------------------------- plot(p, c("NAME_1", "NAME_2"), col=rainbow(25)) ## ----maps_4b, fig.width=10---------------------------------------------------- par(mfrow=c(1,2)) m <- c(3.1, 3.1, 2.1, 2.1) plot(p, "NAME_1", col=rainbow(25), mar=m, plg=list(x="topright"), pax=list(las=1)) plot(p, "NAME_2", col=rainbow(25), mar=m, plg=list(x="topright", cex=.75), pax=list(las=1)) ## ----maps_5, fig.width=10----------------------------------------------------- par(mfrow=c(1,2)) m <- c(3.1, 3.1, 1.1, 1.1) plot(p, "NAME_1", col=rainbow(25), mar=m, plg=list(x="topright", title="District", bty = "o"), main="", axes=FALSE) axis(1, at=c(5,7)); axis(1) axis(2, at=c(49,51)); axis(2, las=1) plot(p, "NAME_2", col=rainbow(25), mar=m, plg=list(x="topright", cex=.75, title="Canton", bty = "o"), main="", axes=FALSE) axis(1, at=c(5, 7)); axis(1) ## ----maps_6------------------------------------------------------------------- d <- aggregate(p, "NAME_1") plot(p, col="light blue", lty=2, border="red", lwd=2) lines(d, lwd=5) lines(d, col="white", lwd=1) text(p, "NAME_2", cex=.8, halo=TRUE) ## ----maps_10------------------------------------------------------------------ f <- system.file("ex/elev.tif", package="terra") r <- rast(f) ## ----maps_11------------------------------------------------------------------ plot(r) ## ----maps_12------------------------------------------------------------------ plot(r) lines(p, lwd=2) set.seed(12) xy <- spatSample(r, 20, "random", na.rm=TRUE, xy=TRUE) points(xy, pch=20, col="red", cex=2) ## ----maps_13------------------------------------------------------------------ m <- c(3.1, 3.1, 1.1, 1.1) plot(r, type="interval", plg=list(x="topright"), mar=m) ## ----maps_14------------------------------------------------------------------ rr <- round(r/100) plot(rr, plg=list(x="topright"), mar=m) ## ----maps_15, fig.height=5, fig.width=9--------------------------------------- x <- classify(r, c(140, 300, 400, 550)) levels(x) <- data.frame(id=0:2, elevation=c("low", "intermediate", "high")) is.factor(x) x plot(x, col=c("green", "blue", "light gray")) ## ----maps_16------------------------------------------------------------------ library(terra) b <- rast(system.file("ex/logo.tif", package="terra")) plot(b) ## ----maps_17------------------------------------------------------------------ r <- rast(p, res=0.01 ) values(r) <- 1:ncell(r) r <- mask(r, p) ## ----maps_20------------------------------------------------------------------ plotRGB(b, r=1, g=2, b=3) ## ----maps_data---------------------------------------------------------------- library(terra) f <- system.file("ex/lux.shp", package="terra") p <- vect(f) ## ----maps_21------------------------------------------------------------------ library(maptiles) bg <- get_tiles(ext(p)) plotRGB(bg) lines(p, col="blue", lwd=3) ## ----leaflet, message=FALSE--------------------------------------------------- library(leaflet) m <- plet(p) m