Skip to content

Instantly share code, notes, and snippets.

@mutolisp
Created October 14, 2020 03:24
Show Gist options
  • Save mutolisp/f12df0a2c30ba2187cc72c02fb11b57a to your computer and use it in GitHub Desktop.
Save mutolisp/f12df0a2c30ba2187cc72c02fb11b57a to your computer and use it in GitHub Desktop.
20201014_data_visualisation2.r
library(sp)
library(gstat)
library(raster)
graycol <- gray.colors(4, 0.55, 0.95)
# use IDW to generate zn.idw
data(meuse)
coordinates(meuse) <- c('x', 'y')
data(meuse.grid)
gridded(meuse.grid) <- c('x', 'y')
idw.out <- gstat::idw(zinc ~ 1, meuse,
meuse.grid, idp = 2.5)
# idw.out.rast <- raster(idw.out)
# idw.out is an object of SpatialPixelsDataFrame
par(mar = c(1,1,1,1))
image(idw.out)
# col = graycol,
# breaks = log(c(100, 200, 400,
800, 1800)))
data(meuse.riv)
meuse.lst <- list(Polygons(list(Polygon(meuse.riv)),
"meuse.riv"))
meuse.pol <- SpatialPolygons(meuse.lst)
plot(meuse.pol, add = TRUE)
plot(meuse, pch = 1, cex = sqrt(meuse$zinc)/20, add = TRUE)
legVals <- c(100, 200, 500, 1000, 2000)
legend(locator(1), legend = legVals, pch = 1,
pt.cex = sqrt(legVals)/20,
bty = "n", title = "measured")
legend("topleft", legend =
c("100-200", "200-400", "400-800",
"800-1800"),
fill = grays, bty = "n", title = "interpolated")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment