diff --git a/articles/retiring_rgdal_geos_1.html b/articles/retiring_rgdal_geos_1.html index 5e316f6..598cb0e 100644 --- a/articles/retiring_rgdal_geos_1.html +++ b/articles/retiring_rgdal_geos_1.html @@ -298,7 +298,7 @@
## Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
-nc <- as(read_sf(system.file("gpkg/nc.gpkg", package="sf")), "Spatial")
nc <- as(st_read(system.file("gpkg/nc.gpkg", package="sf")), "Spatial")
+## Reading layer `nc.gpkg' from data source
+## `/home/runner/work/_temp/Library/sf/gpkg/nc.gpkg' using driver `GPKG'
+## Simple feature collection with 100 features and 14 fields
+## Geometry type: MULTIPOLYGON
+## Dimension: XY
+## Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
+## Geodetic CRS: NAD27
The basic plot
command on a Spatial
object
gives just the geometry, without axes:
+plot(meuse)
axes can be added when
-axes=TRUE
is given; plot elements can be added incrementally:+plot(meuse, pch = 1, cex = sqrt(meuse$zinc)/12, axes = TRUE) v = c(100,200,400,800,1600) legend("topleft", legend = v, pch = 1, pt.cex = sqrt(v)/12) plot(meuse.riv, add = TRUE, col = grey(.9, alpha = .5))
For local projection systems, such as in this case
-+proj4string(meuse)
## [1] "+proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"
the aspect ratio is set to 1, to make sure that one unit north equals @@ -148,17 +155,17 @@
Using base plot -
+crs.longlat = CRS("+init=epsg:4326")
-## Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is ## deprecated. It might return a CRS with a non-EPSG compliant axis order.
+meuse.longlat = spTransform(meuse, crs.longlat) plot(meuse.longlat, axes = TRUE)
which looks different from the plot where one degree north (latitude) equals one degree east (longitude):
-+ @@ -171,7 +178,7 @@Graticules
+-par(mar = c(0, 0, 1, 0)) library(methods) # as plot(as(meuse, "Spatial"), expandBB = c(.05, 0, 0, 0)) @@ -180,7 +187,7 @@
Graticulestext(labels(gridlines(meuse)), col = grey(.7)) title("default gridlines with Meuse projected data")
+par(mar = c(0, 0, 1, 0)) grd <- gridlines(meuse.longlat) grd_x <- spTransform(grd, CRS(proj4string(meuse))) @@ -190,12 +197,12 @@
Graticulestext(labels(grd_x, crs.longlat), col = grey(.7))
-## Warning in labels.SpatialLines(grd_x, crs.longlat): this labels method is meant ## to operate on SpatialLines created with sp::gridlines
+title("longitude latitude gridlines and labels")
These lines look pretty straight, because it concerns a small area. For
-+# demonstrate axis labels with angle, both sides: maps2sp = function(xlim, ylim, l.out = 100, clip = TRUE) { @@ -206,7 +213,7 @@
Graticulespar(mar = c(0, 0, 1, 0)) m = maps2sp(c(-100,-20), c(10,55))
-## Loading required package: maps
+sp = SpatialPoints(rbind(c(-101,9), c(-101,55), c(-19,9), c(-19,55)), CRS("+init=epsg:4326")) laea = CRS("+proj=laea +lat_0=30 +lon_0=-40") m.laea = spTransform(m, laea) @@ -219,14 +226,14 @@
Graticulestext(labels(gl.laea, crs.longlat))
-## Warning in labels.SpatialLines(gl.laea, crs.longlat): this labels method is ## meant to operate on SpatialLines created with sp::gridlines
+-## Warning in labels.SpatialLines(gl.laea, crs.longlat, side = 3:4): this labels ## method is meant to operate on SpatialLines created with sp::gridlines
+-title("curved text label demo")
+# polar: par(mar = c(0, 0, 1, 0)) pts=SpatialPoints(rbind(c(-180,-70),c(0,-70),c(180,-89),c(180,-70)), CRS("+init=epsg:4326")) @@ -238,18 +245,18 @@
Graticulesl = labels(gl.polar, crs.longlat, side = 3)
-## Warning in labels.SpatialLines(gl.polar, crs.longlat, side = 3): this labels ## method is meant to operate on SpatialLines created with sp::gridlines
+l$pos = NULL # pos is too simple, use adj: text(l, adj = c(0.5, -0.5), cex = .8) l = labels(gl.polar, crs.longlat, side = 4)
-## Warning in labels.SpatialLines(gl.polar, crs.longlat, side = 4): this labels ## method is meant to operate on SpatialLines created with sp::gridlines
+-l$srt = 0 # otherwise they end up upside-down text(l, cex = .8) title("grid line labels on polar projection, epsg 3031")
+par(mar = c(0, 0, 1, 0)) m = maps2sp(xlim = c(-180,180), ylim = c(-90,-70), clip = FALSE) gl = gridlines(m, easts = seq(-180,180,20)) @@ -261,14 +268,14 @@
Graticulesl = labels(gl.polar, crs.longlat, side = 3)
-## Warning in labels.SpatialLines(gl.polar, crs.longlat, side = 3): this labels ## method is meant to operate on SpatialLines created with sp::gridlines
+# pos is too simple here, use adj: l$pos = NULL text(l, adj = c(0.5, -0.3), cex = .8) l = labels(gl.polar, crs.longlat, side = 2)
-## Warning in labels.SpatialLines(gl.polar, crs.longlat, side = 2): this labels ## method is meant to operate on SpatialLines created with sp::gridlines
+@@ -279,19 +286,19 @@l$srt = 0 # otherwise they are upside-down text(l, cex = .8) title("grid line labels on polar projection, epsg 3031")
Other spatial objects in base plot
The following plot shows polygons with county name as labels at their center point:
-+par(mar = c(0, 0, 1, 0)) plot(nc) invisible(text(coordinates(nc), labels=as.character(nc$NAME), cex=0.4))
This plot of a
-SpatialPolygonsDataFrame
uses grey shades:+names(nc)
-## [1] "AREA" "PERIMETER" "CNTY_" "CNTY_ID" "NAME" "FIPS" ## [7] "FIPSNO" "CRESS_ID" "BIR74" "SID74" "NWBIR74" "BIR79" ## [13] "SID79" "NWBIR79"
+rrt <- nc$SID74/nc$BIR74 brks <- quantile(rrt, seq(0,1,1/7)) cols <- grey((length(brks):2)/length(brks)) @@ -301,7 +308,7 @@
Other spatial objects in base plot
The following plot shows a
-SpatialPolygonsDataFrame
, using line densities+rrt <- nc$SID74/nc$BIR74 brks <- quantile(rrt, seq(0,1,1/7)) cols <- grey((length(brks):2)/length(brks)) @@ -310,14 +317,14 @@
Other spatial objects in base plotplot(nc, density=dens[findInterval(rrt, brks, all.inside=TRUE)])
Plot/image of a grid file, using base plot methods:
-+-image(meuse.grid)
+ -+ @@ -330,7 +337,7 @@using lattice plot (spplot)
The following plot colours points with a legend in the plotting area and adds scales:
-+@@ -338,14 +345,14 @@spplot(meuse, "zinc", do.log = TRUE, key.space=list(x = 0.1, y = 0.95, corner = c(0, 1)), scales=list(draw = TRUE))
using lattice plot (spplot)The following plot has coloured points plot with legend in plotting area and scales; it has a non-default number of cuts with user-supplied legend entries: -
+spplot(meuse, "zinc", do.log = TRUE, key.space=list(x=0.2,y=0.9,corner=c(0,1)), scales=list(draw = TRUE), cuts = 3, legendEntries = c("low", "intermediate", "high"))
The following plot adds a scale bar and north arrow:
-+scale = list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(178600,332490), scale = 500, fill=c("transparent","black")) text1 = list("sp.text", c(178600,332590), "0") @@ -358,7 +365,7 @@
using lattice plot (spplot) main = "Zinc (top soil)")
The following plot has north arrow and text outside panels
-+rv = list("sp.polygons", meuse.riv, fill = "lightblue") scale = list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(180500,329800), scale = 500, fill=c("transparent","black"), which = 1) @@ -374,7 +381,7 @@
using lattice plot (spplot)
The same plot; north arrow now inside panel, with custom panel function instead of sp.layout
-+spplot(meuse, "zinc", panel = function(x, y, ...) { sp.polygons(meuse.riv, fill = "lightblue") SpatialPolygonsRescale(layout.scale.bar(), offset = c(179900,329600), @@ -393,7 +400,7 @@
argument in a layout component (ifusing lattice plot (spplot)which
which=4
was set as list component of sp.layout, the river would as well be drawn only in that (last) panel) -+rv = list("sp.polygons", meuse.riv, fill = "lightblue") scale = list("SpatialPolygonsRescale", layout.scale.bar(), offset = c(180500,329800), scale = 500, fill=c("transparent","black"), which = 4) @@ -410,7 +417,7 @@
using lattice plot (spplot)
Comparing four kriging varieties in a multi-panel plot with shared scale:
-+rv = list("sp.polygons", meuse.riv, fill = "blue", alpha = 0.1) pts = list("sp.points", meuse, pch = 3, col = "grey", alpha = .5) text1 = list("sp.text", c(180500,329900), "0", cex = .5, which = 4) @@ -448,19 +455,19 @@
using lattice plot (spplot)
Reuse these results; universal kriging standard errors; grid plot with point locations and polygon (river):
-+-rv = list("sp.polygons", meuse.riv, fill = "blue", alpha = 0.1) pts = list("sp.points", meuse, pch = 3, col = "grey", alpha = .7) spplot(zn.uk, "var1.pred", sp.layout = list(rv, scale, text1, text2, pts), main = "log(zinc); universal kriging using sqrt(dist to Meuse)")
+-zn.uk[["se"]] = sqrt(zn.uk[["var1.var"]]) spplot(zn.uk, "se", sp.layout = list(rv, pts), main = "log(zinc); universal kriging standard errors")
+-arrow = list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(-76,34), scale = 0.5, which = 2) spplot(nc, c("SID74", "SID79"), names.attr = c("1974","1979"), @@ -468,7 +475,7 @@
using lattice plot (spplot) main = "SIDS (sudden infant death syndrome) in North Carolina", sp.layout = list(arrow), as.table = TRUE)
+arrow = list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(-76,34), scale = 0.5, which = 2) #scale = list("SpatialPolygonsRescale", layout.scale.bar(), @@ -483,7 +490,7 @@
using lattice plot (spplot) sp.layout = arrow, as.table = TRUE)
Bubble plots for cadmium and zinc:
-+b1 = bubble(meuse, "cadmium", maxsize = 1.5, main = "cadmium concentrations (ppm)", key.entries = 2^(-1:4)) b2 = bubble(meuse, "zinc", maxsize = 1.5, main = "zinc concentrations (ppm)", @@ -492,7 +499,7 @@
using lattice plot (spplot)print(b2, split = c(2,1,2,1), more = FALSE)
Factor variables using
-spplot
:+# create two dummy factor variables, with equal labels: set.seed(31) nc$f = factor(sample(1:5, 100,replace = TRUE),labels=letters[1:5]) @@ -514,18 +521,18 @@
Interactive maps: leaflet, mapviewR packages leaflet and mapview provide interactive, browser-based maps building upon the leaflet javascript library. Example with points, grid and polygons follow: -
+ -+ -+Mapview also allows grids of view that are synced
-diff --git a/pkgdown.yml b/pkgdown.yml index 89e44d0..44626e0 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -5,5 +5,5 @@ articles: CRS_warnings: CRS_warnings.html retiring_rgdal_geos_1: retiring_rgdal_geos_1.html sp_gallery: sp_gallery.html -last_built: 2024-05-06T18:42Z +last_built: 2024-05-06T19:03Z+m1 <- mapview(meuse, zcol = "soil", burst = TRUE, legend = TRUE) m2 <- mapview(meuse, zcol = "lead", legend = TRUE) m3 <- mapview(meuse, zcol = "landuse", map.types = "Esri.WorldImagery", legend = TRUE) @@ -537,7 +544,7 @@
Interactive maps: leaflet, mapview
SessionInfo
-++## [10] stats4_4.4.0 proxy_0.4-27 spacetime_1.3-1 +## [13] highr_0.10 xts_0.13.2 KernSmooth_2.23-22 +## [16] satellite_1.0.5 desc_1.4.3 leaflet_2.2.2 +## [19] uuid_1.2-0 lifecycle_1.0.4 farver_2.1.1 +## [22] compiler_4.4.0 FNN_1.1.4 textshaping_0.3.7 +## [25] munsell_0.5.1 terra_1.7-71 codetools_0.2-20 +## [28] htmltools_0.5.8.1 class_7.3-22 sass_0.4.9 +## [31] yaml_2.3.8 pkgdown_2.0.9 jquerylib_0.1.4 +## [34] classInt_0.4-10 cachem_1.0.8 brew_1.0-10 +## [37] digest_0.6.35 purrr_1.0.2 fastmap_1.1.1 +## [40] grid_4.4.0 colorspace_2.1-0 cli_3.6.2 +## [43] magrittr_2.0.3 base64enc_0.1-3 leafem_0.2.3 +## [46] e1071_1.7-14 scales_1.3.0 rmarkdown_2.26 +## [49] ragg_1.3.0 zoo_1.8-12 png_0.1-8 +## [52] memoise_2.0.1 evaluate_0.23 knitr_1.46 +## [55] rlang_1.1.3 Rcpp_1.0.12 leafpop_0.1.0 +## [58] glue_1.7.0 DBI_1.2.2 svglite_2.1.3 +## [61] jsonlite_1.8.8 R6_2.5.1 systemfonts_1.0.6 +## [64] fs_1.6.4 intervals_0.15.4 units_0.8-5## R version 4.4.0 (2024-04-24) ## Platform: x86_64-pc-linux-gnu @@ -567,27 +574,25 @@
SessionInfo## [1] xfun_0.43 bslib_0.7.0 raster_3.6-26 ## [4] htmlwidgets_1.6.4 lattice_0.22-6 leaflet.providers_2.0.0 ## [7] vctrs_0.6.5 tools_4.4.0 crosstalk_1.2.1 -## [10] stats4_4.4.0 tibble_3.2.1 proxy_0.4-27 -## [13] spacetime_1.3-1 fansi_1.0.6 highr_0.10 -## [16] xts_0.13.2 pkgconfig_2.0.3 KernSmooth_2.23-22 -## [19] satellite_1.0.5 desc_1.4.3 uuid_1.2-0 -## [22] leaflet_2.2.2 lifecycle_1.0.4 farver_2.1.1 -## [25] compiler_4.4.0 FNN_1.1.4 textshaping_0.3.7 -## [28] munsell_0.5.1 terra_1.7-71 codetools_0.2-20 -## [31] htmltools_0.5.8.1 class_7.3-22 sass_0.4.9 -## [34] yaml_2.3.8 pillar_1.9.0 pkgdown_2.0.9 -## [37] jquerylib_0.1.4 classInt_0.4-10 cachem_1.0.8 -## [40] brew_1.0-10 digest_0.6.35 purrr_1.0.2 -## [43] fastmap_1.1.1 grid_4.4.0 colorspace_2.1-0 -## [46] cli_3.6.2 magrittr_2.0.3 base64enc_0.1-3 -## [49] utf8_1.2.4 leafem_0.2.3 e1071_1.7-14 -## [52] scales_1.3.0 rmarkdown_2.26 ragg_1.3.0 -## [55] zoo_1.8-12 png_0.1-8 memoise_2.0.1 -## [58] evaluate_0.23 knitr_1.46 rlang_1.1.3 -## [61] leafpop_0.1.0 Rcpp_1.0.12 glue_1.7.0 -## [64] DBI_1.2.2 svglite_2.1.3 jsonlite_1.8.8 -## [67] R6_2.5.1 systemfonts_1.0.6 fs_1.6.4 -## [70] intervals_0.15.4 units_0.8-5