@@ -90,14 +90,12 @@
|
|
90
90
|
###################################################
|
91
91
|
### code chunk number 21: vis.Rnw:537-538
|
92
92
|
###################################################
|
93
|
-
library(maptools) # requires sp
|
94
93
|
|
95
94
|
|
96
95
|
###################################################
|
97
96
|
### code chunk number 22: vis.Rnw:543-567
|
98
97
|
###################################################
|
99
|
-
nc <-
|
100
|
-
proj4string=CRS("+proj=longlat +datum=NAD27"))
|
98
|
+
nc <- as(sf::st_read(system.file("shape/nc.shp", package="sf")[1]), "Spatial")
|
101
99
|
rrt <- nc$SID74/nc$BIR74
|
102
100
|
brks <- quantile(rrt, seq(0,1,1/5))
|
103
101
|
library(RColorBrewer)
|
@@ -111,20 +109,19 @@
|
|
111
109
|
###################################################
|
112
110
|
### code chunk number 23: vis.Rnw:598-617 (eval = FALSE)
|
113
111
|
###################################################
|
114
|
-
library(maptools)
|
115
112
|
library(maps)
|
116
113
|
wrld <- map("world", interior=FALSE, xlim=c(-179,179),
|
117
114
|
ylim=c(-89,89), plot=FALSE)
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
library(sf)
|
116
|
+
wrld_sf = st_as_sf(wrld, fill=FALSE, crs=llCRS)
|
117
|
+
wrld_sf = st_wrap_dateline(wrld_sf) # avoiding maptools::pruneMap
|
118
|
+
wrld_sp = as(wrld_sf[!st_is_empty(wrld_sf),], "Spatial")
|
121
119
|
prj_new <- CRS("+proj=moll +ellps=WGS84")
|
122
|
-
|
123
|
-
wrld_proj <- spTransform(wrld_sp, prj_new)
|
120
|
+
wrld_proj <- as(st_transform(st_as_sf(wrld_sp), st_crs(prj_new)), "Spatial") #spTransform(wrld_sp, prj_new)
|
124
121
|
wrld_grd <- gridlines(wrld_sp, easts=c(-179,seq(-150,150,50), 179.5), norths=seq(-75,75,15), ndiscr=100)
|
125
|
-
wrld_grd_proj <- spTransform(wrld_grd, prj_new)
|
122
|
+
wrld_grd_proj <- as(st_transform(st_as_sf(wrld_grd), st_crs(prj_new)), "Spatial") #spTransform(wrld_grd, prj_new)
|
126
123
|
at_sp <- gridat(wrld_sp, easts=0, norths=seq(-75,75,15), offset=0.3)
|
127
|
-
at_proj <- spTransform(at_sp, prj_new)
|
124
|
+
at_proj <- as(st_transform(st_as_sf(at_sp), st_crs(prj_new)), "Spatial") #spTransform(at_sp, prj_new)
|
128
125
|
plot(wrld_proj, col="grey60")
|
129
126
|
plot(wrld_grd_proj, add=TRUE, lty=3, col="grey70")
|
130
127
|
text(coordinates(at_proj), pos=at_proj$pos, offset=at_proj$offset, labels=parse(text=as.character(at_proj$labels)), cex=0.6)
|
@@ -245,14 +242,16 @@
|
|
245
242
|
###################################################
|
246
243
|
### code chunk number 39: vis.Rnw:1025-1051
|
247
244
|
###################################################
|
248
|
-
|
245
|
+
grys0 <- brewer.pal(9, "Reds")
|
249
246
|
data(meuse.grid)
|
250
247
|
coordinates(meuse.grid) <- c("x", "y")
|
251
248
|
meuse.grid <- as(meuse.grid, "SpatialPixelsDataFrame")
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
249
|
+
cl0 <- contourLines(as.image.SpatialGridDataFrame(meuse.grid["dist"]))
|
250
|
+
cl1 = lapply(cl0, function(x) cbind(x$x, x$y)) # avoiding maptools::ContourLines2SLDF
|
251
|
+
cl2 = split(cl1, sapply(cl0, "[[", "level"))
|
252
|
+
cl3 = st_sfc(lapply(cl2, st_multilinestring))
|
253
|
+
cl = as(st_as_sf(cl3, level=names(cl2)), "Spatial")
|
254
|
+
print(spplot(cl, colorkey=list(height=0.8, width=0.6), at=as.numeric(cl$level), col.regions=grys0), split = c(1,1,3,1), more=TRUE)
|
256
255
|
grys <- brewer.pal(6, "Reds")
|
257
256
|
cuts = (0:5)/5
|
258
257
|
print(spplot(meuse.grid, "dist", at=cuts
|
@@ -267,12 +266,6 @@
|
|
267
266
|
###################################################
|
268
267
|
### code chunk number 40: vis.Rnw:1098-1105
|
269
268
|
###################################################
|
270
|
-
library(maptools)
|
271
|
-
data(meuse.grid)
|
272
|
-
coordinates(meuse.grid) <- c("x", "y")
|
273
|
-
meuse.grid <- as(meuse.grid, "SpatialPixelsDataFrame")
|
274
|
-
im <- as.image.SpatialGridDataFrame(meuse.grid["dist"])
|
275
|
-
cl <- ContourLines2SLDF(contourLines(im))
|
276
269
|
spplot(cl)
|
277
270
|
|
278
271
|
|
@@ -346,11 +339,7 @@
|
|
346
339
|
###################################################
|
347
340
|
### code chunk number 52: vis.Rnw:1471-1475
|
348
341
|
###################################################
|
349
|
-
|
350
|
-
prj <- CRS("+proj=longlat +datum=NAD27")
|
351
|
-
nc_shp <- system.file("shapes/sids.shp", package="maptools")[1]
|
352
|
-
nc <- readShapePoly(nc_shp, proj4string=prj)
|
353
|
-
|
342
|
+
nc <- as(sf::st_read(system.file("shape/nc.shp", package="sf")[1]), "Spatial")
|
354
343
|
|
355
344
|
###################################################
|
356
345
|
### code chunk number 53: vis.Rnw:1477-1479 (eval = FALSE)
|
@@ -473,3 +462,10 @@
|
|
473
462
|
spplot(meuse.grid, "dist", colorkey=list(labels=list(at=cuts)), at=cuts)
|
474
463
|
|
475
464
|
|
465
|
+
|
466
|
+
(sI <- sessionInfo()) # check: no sp?
|
467
|
+
|
468
|
+
"rgdal" %in% c(names(sI$otherPkgs), names(sI$loadedOnly))
|
469
|
+
"rgeos" %in% c(names(sI$otherPkgs), names(sI$loadedOnly))
|
470
|
+
"maptools" %in% c(names(sI$otherPkgs), names(sI$loadedOnly))
|
471
|
+
|