-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Rhistory
512 lines (512 loc) · 18 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# View the metadata of the layerstacked images
metaLyrStack <- lyrStack
metaLyrStack
# Select RED(B5) from stack
lyrStack[[4]]
plot(lyrStack[[7]], main = "Landsat 8 Band 5")
# Plot RGB Natural color
plotRGB(lyrStack, 4,3,2, scale=65535, main = "L8 Natural Color: BGR")
# Plot RGB Natural color
plotRGB(lyrStack, 4,3,2, scale=65535, main = "L8 Natural Color: BGR", stretch = 'lin')
# Save the file to disk
writeRaster(lyrStack, "L8LayerStack.tif", format="GTiff", datatype='INT2U', overwrite=TRUE)
# Save the file to disk
writeRaster(lyrStack, "L8NgLayerStack.tif", format="GTiff", datatype='INT2U', overwrite=TRUE)
getwd()
content <- list.files()
length(content)
getwd()
setwd("D:/STUDY/4.GIS/G I S 4.1/2.Geostats/0x520x")
getwd()
content <- list.files()
length(content)
setwd("D:/STUDY/4.GIS/G I S 4.1/2.Geostats/0x520x/INPUT/L8NgaraTiffs")
getwd()
content <- list.files()
length(content)
layerStacked <- stack("L8NgLayerStack.tif")
layerStacked
# plot a single band
plot(layerStacked[[5]], main = "NIR Band")
# 2. By shapefile
list.files()
# load shp
shp <- readOGR("shapefiles/Ngara.shp")
shp
plotRGB(layerStacked, 4,3,2, scale=65535, stretch = 'lin', main = "RGB Croped")
plot(shp, add = TRUE)
croppedLyrStck <- crop(layerStacked, shp)
# load shp
shp <- readOGR("shapefiles - Reprj/Ngara.shp")
shp
plotRGB(layerStacked, 4,3,2, scale=65535, stretch = 'lin', main = "RGB Croped")
plot(shp, add = TRUE)
croppedLyrStck <- crop(layerStacked, shp)
# load shp
shp <- readOGR("shapefiles - Reprj/Ngara.shp")
shp
plotRGB(layerStacked, 4,3,2, scale=65535, stretch = 'lin', main = "RGB Croped")
plot(shp, add = TRUE)
croppedLyrStck <- crop(layerStacked, shp)
# load shp
shp <- readOGR("shapefiles/Ngara.shp")
shp
plotRGB(layerStacked, 4,3,2, scale=65535, stretch = 'lin', main = "RGB Croped")
plot(shp, add = TRUE)
croppedLyrStck <- crop(layerStacked, shp)
croppedLyrStck
# load shp
shp <- readOGR("shapefiles - Reprj/Ngara.shp")
shp
plotRGB(layerStacked, 4,3,2, scale=65535, stretch = 'lin', main = "RGB Croped")
plot(shp, add = TRUE)
croppedLyrStck <- crop(layerStacked, shp)
# 4. Logit transform
logit <- log(meuse$zinc/1--(meuse$zinc))
# 4. Logit transform
logit <- log(meuse$zinc/(1--(meuse$zinc))
# 4. Logit transform
logit <- log(meuse$zinc/(1--meuse$zinc))
# Clear memory
rm(list=ls(all=TRUE))
#Load existing/install missing libraries
if (!require("pacman", "rcompanion")) install.packages("pacman", "rcompanion")
install.packages("pacman", "rcompanion")
library(sp)
library(rcompanion)
data <- data(meuse)
df <- meuse
knitr::kable(head(df, n=3), align = 'l')
# Normal QQ plots
qqnorm(meuse$copper, main='Copper in Meuse River', xlab = 'Copper', ylab = 'Frequency')
qqline(meuse$copper)
# Both Normal and Histogram at once using the rcompanion package
install.packages("rcompanion")
install.packages("rcompanion")
help(plotNormalHistogram)
plotNormalHistogram(
meuse$zinc,
main = "Original Data",
prob = FALSE,
col = "gray",
linecol = "blue",
)
help(plotNormalHistogram)
plotNormalHistogram(
meuse$zinc,
main = "Original Data",
prob = FALSE,
col = "gray",
linecol = "blue",
)
# Data transformation
#Divide the screen in 2 columns and 2 lines
par(mfrow=c(2,2))
# Plot original Data
plotNormalHistogram(meuse$zinc, main = "Original Data")
# Both Normal and Histogram at once using the rcompanion package
install.packages("rcompanion")
plotNormalHistogram(
meuse$zinc,
main = "Original Data",
prob = FALSE,
col = "gray",
linecol = "blue",
)
max(meuse$zinc)
meuse$zinc
meuse$zinc
max(meuse$zinc)
library(rcompanion)
# 3. Angular
angular <- asin(sqrt(meuse$zinc / max(meuse$zinc)))
plotNormalHistogram(angular, main = "Angular Trnsfrm")
# 4. Logit transform
logit <- log(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Angular Trnsfrm")
# 1 Log transform(NB : log(0) is infinity, so avoid that by adding 1 to 0 numbers)
logZinc <- log(meuse$zinc + 1)
plotNormalHistogram(logZinc, main = "Log Transform")
# Data transformation
#Divide the screen in 2 columns and 2 lines
par(mfrow=c(2,2))
# Plot original Data
plotNormalHistogram(meuse$zinc, main = "Original Data")
# 1 Log transform(NB : log(0) is infinity, so avoid that by adding 1 to 0 numbers)
logZinc <- log(meuse$zinc + 1)
plotNormalHistogram(logZinc, main = "Log Transform")
# 2. Sqrt
sqroot <- sqrt(meuse$zinc)
plotNormalHistogram(sqroot, main = "Sqrt Transform")
# 3. Angular
angular <- asin(sqrt(meuse$zinc / max(meuse$zinc)))
plotNormalHistogram(angular, main = "Angular Trnsfrm")
# 4. Logit transform
logit <- log(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Angular Trnsfrm")
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 4. Logit transform
logit <- log(meuse$zinc/(1-meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 4. Logit transform
logit <- log(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 4. Logit transform
logit <- log10(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
log(0)
log(0+1)
# 4. Logit transform
logit <- log10(meuse$zinc/(1-meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 4. Logit transform
logit <- log10(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 4. Logit transform
logit <- log(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# Data transformation
#Divide the screen in 2 columns and 2 lines
par(mfrow=c(2,2))
# 4. Logit transform
logit <- log10(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit(10) Trnsfrm")
logit <- log(meuse$zinc/(1--meuse$zinc))
plotNormalHistogram(logit, main = "Logit Trnsfrm")
# 3. Angular2
angular <- asin(sqrt(meuse$zinc / max(meuse$zinc))*2/pi)
plotNormalHistogram(angular, main = "Angular Trnsfrm")
# 3. Angular2
angular <- asin(sqrt(meuse$zinc / 100)*2/pi)
plotNormalHistogram(angular, main = "Angular Trnsfrm")
meuse$zinc
# Measure of Central Tendency
# 1 Mean of
logZinc <- log(meuse$zinc + 1)
mlogZinc <- mean(logZinc)
plotNormalHistogram(mlogZinc, main = "Log Transform")
mlogZinc
plotNormalHistogram(logZinc, main = "Log Transform")
msqrt <- mean(sqroot)
msqrt
plotNormalHistogram(angular,col = "yellow", main = "Angular Trnsfrm")
median((mlmogZinc))
median(mlogZinc)
median(logZinc)
summary(mean(angular), median(angular))
median(angular)
# 3. Angular
angular <- asin(sqrt(meuse$zinc / max(meuse$zinc)))
plotNormalHistogram(angular, main = "Angular Trnsfrm")
median(sqroot)
median(angular)
mean(angular)
mean(logit)
median(logit)
Summary(logit)
summary(logit)
summary(logit, sqroot)
summary(sqroot)
mean(mlogZinc)-median(mlogZinc)
mean(mlogZinc)
median(mlogZinc)
mean(logZinc)-median(logZinc)
# Import the geostats libraries
# library(sp)
library(lattice) #for plotting graphics
#call the meuse R data
data(meuse)
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$soil) <- paste("soil", levels(meuse$soil), sep="")
str(meuse)
palette(trellis.par.get("superpose.symbol")$col)
plot(zinc~dist, meuse, pch=as.integer(ffreq), col=soil)
# Add lattice legend at the topright
legend("topright", col=c(rep(1, nlevels(meuse$ffreq)), 1:nlevels(meuse$soil)),
pch=c(1:nlevels(meuse$ffreq), rep(1, nlevels(meuse$soil))), bty="n",
legend=c(levels(meuse$ffreq), levels(meuse$soil)))
panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
}
xyplot(log(zinc)~dist | ffreq, meuse, groups=soil, panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
},
auto.key=TRUE)
# Clear memory
rm(list=ls(all=TRUE))
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$soil) <- paste("soil", levels(meuse$soil), sep="")
str(meuse)
palette(trellis.par.get("superpose.symbol")$col)
plot(zinc~dist, meuse, pch=as.integer(ffreq), col=soil)
# Add lattice legend at the topright
legend("topright", col=c(rep(1, nlevels(meuse$ffreq)), 1:nlevels(meuse$soil)),
pch=c(1:nlevels(meuse$ffreq), rep(1, nlevels(meuse$soil))), bty="n",
legend=c(levels(meuse$ffreq), levels(meuse$soil)))
panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
}
xyplot(log(zinc)~dist | ffreq, meuse, groups=soil, panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
},
auto.key=TRUE)
plot(zinc~dist, meuse, pch=as.integer(ffreq), col=soil)
# Import the geostats libraries
# library(sp)
library(lattice) #for plotting graphics
#call the meuse R data
data(meuse)
libary(sp)
#call the meuse R data
data(meuse)
library(sp)
#call the meuse R data
data(meuse)
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$soil) <- paste("soil", levels(meuse$soil), sep="")
str(meuse)
palette(trellis.par.get("superpose.symbol")$col)
plot(zinc~dist, meuse, pch=as.integer(ffreq), col=soil)
# Add lattice legend at the topright
legend("topright", col=c(rep(1, nlevels(meuse$ffreq)), 1:nlevels(meuse$soil)),
pch=c(1:nlevels(meuse$ffreq), rep(1, nlevels(meuse$soil))), bty="n",
legend=c(levels(meuse$ffreq), levels(meuse$soil)))
# Import the 2 packages
library(sp)
library(lattice)
# call the meuse data
data(meuse)
coordinates(meuse) <- c("x", "y")
# Predict topsoil zinc concentration using spplot & bubble plots
spplot(meuse, "zinc", do.log = T, colorkey = TRUE)
bubble(meuse, "zinc", do.log = T, key.space = "right")
libary(ggplot2)
library(scales)
install.packages(RColorBrewer)
install.packages("RColorBrewer")
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc)
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc, breaks = 0,200,400,800,1200,2000)
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc, breaks = c(0,200,400,800,1200,2000))
zinc.plot <- ggplot(aes(x=x, y=y), data = meuse)
library(ggplot2)
zinc.plot <- ggplot(aes(x=x, y=y), data = meuse)
load(system.file("data", "meuse.rda", package = "sp"))
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc, breaks = c(0,200,400,800,1200,2000))
zinc.plot <- ggplot(aes(x=x, y=y), data = meuse)
zinc.plot<-zinc.plot+geom_point(aes(color = zinc_cat))
zinc.plot <- zinc.plot+coord_equal()
zinc.plot <- zinc.plot+scale_color_brewer(pallete = "YlGnBu")
install.packages("RColorBrewer")
zinc.plot <- zinc.plot+scale_color_brewer(pallete = "YlGnBu")
zinc.plot
# Lineaar Modelling of spatila Data to explain the distribution of zinc concentration within the site.
# Clear memory and load aster data packages
rm(list = ls(all=TRUE))
library(sp) # Contains the Meuse data
library(lattice) #plotting graphics
library(ggplot2)
library(scales)
library(gstat)
library(sf)
# 3. Spatial Data frames
data(meuse)## loading data
# Transform into a collection of simple features(SF) with attributes and geometries in the form of a df.
summary(meuse)
class(meuse)
meuse = st_as_sf(meuse,coords=c("x","y"),remove=FALSE)
#.------- STEP 3. View the spatial dataset on Meuse Map -- #
#1. Loading gridded data
data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
gridded(meuse.grid) = TRUE
class(meuse.grid)
#2. Transform gridded data into Spatial Pixels
meuse.grid = as(meuse.grid, "SpatialPixels")
#4. Plot Zinc concentration on the floodplain along the Meuse River.
meuse.sr = SpatialPolygons(meuse.lst)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
class(meuse.grid)
#2. Transform gridded data into Spatial Pixels
meuse.grid = as(meuse.grid, "SpatialPixels")
#3. loading Meuse river data
data(meuse.riv)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
#4. Plot Zinc concentration on the floodplain along the Meuse River.
meuse.sr = SpatialPolygons(meuse.lst)
image(meuse.grid, col = "yellowgreen")
#5. plot the river data
plot(meuse.sr, col = "grey", add = TRUE)
#6. plot the zinc dataset
plot(meuse[,c('zinc')], add = TRUE, cex=1.5)
# ---------- STEP 4 ----------------- #
# Perform ESDA to visualize the data so that we can assess how to look at the problem.
#1.Transforming back the sf object into a data frame
st_geometry(meuse) = NULL
library(GGally)
st_geometry(meuse) = NULL ## Transforming back the sf object into a data frame
ggpairs(meuse[,3:9]) ## print correlations between quantitative variables
#7. Add title
title("Meuse Data")
#3. loading Meuse river data
data(meuse.riv)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
#4. Plot Zinc concentration on the floodplain along the Meuse River.
meuse.sr = SpatialPolygons(meuse.lst)
image(meuse.grid, col = "yellowgreen")
#5. plot the river data
plot(meuse.sr, col = "grey", add = TRUE)
#6. plot the zinc dataset
plot(meuse[,c('zinc')], add = TRUE, cex=1.5)
#7. Add title
title("Meuse Data")
bubble(meuse, "zinc", do.log = T, key.space = "right")
# Predict topsoil zinc concentration using spplot & bubble plots
spplot(meuse, "zinc", do.log = T, colorkey = TRUE)
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc, breaks = c(0,200,400,800,1200,2000))
class(meuse)
meuse = st_as_sf(meuse,coords=c("x","y"),remove=FALSE)
#.------- STEP 3. View the spatial dataset on Meuse Map -- #
#1. Loading gridded data
data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
gridded(meuse.grid) = TRUE
class(meuse.grid)
#2. Transform gridded data into Spatial Pixels
meuse.grid = as(meuse.grid, "SpatialPixels")
#3. loading Meuse river data
data(meuse.riv)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)),"meuse.riv"))
#4. Plot Zinc concentration on the floodplain along the Meuse River.
meuse.sr = SpatialPolygons(meuse.lst)
image(meuse.grid, col = "yellowgreen")
#5. plot the river data
plot(meuse.sr, col = "grey", add = TRUE)
#6. plot the zinc dataset
plot(meuse[,c('zinc')], add = TRUE, cex=1.5)
#7. Add title
title("Meuse Data")
# ---------- STEP 4 ----------------- #
# Perform ESDA to visualize the data so that we can assess how to look at the problem.
#1.Transforming back the sf object into a data frame
st_geometry(meuse) = NULL
st_geometry(meuse) = NULL ## Transforming back the sf object into a data frame
# ---------- STEP 4 ----------------- #
# Perform ESDA to visualize the data so that we can assess how to look at the problem.
#1.Transforming back the sf object into a data frame
st_geometry(meuse) = NULL
ggpairs(meuse[,3:9]) ## print correlations between quantitative variables
plot_grid(
ggplot(meuse, aes(y = log(zinc), x = ffreq)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = soil)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = lime)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = landuse)) + geom_boxplot(),
nrow = 2, ncol = 2)
library(cowplot) # Tolot the correlations
# Create a new grid function to plot the variables individually
plot_grid(
ggplot(meuse, aes(y = zinc, x = elev)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = elev)) + geom_point(),
nrow = 1, ncol = 2)
plot_grid(
ggplot(meuse, aes(y = zinc, x = dist)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = dist)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = sqrt(dist))) + geom_point(),
nrow = 1, ncol = 3)
plot_grid(
ggplot(meuse, aes(y = log(zinc), x = ffreq)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = soil)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = lime)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = landuse)) + geom_boxplot(),
nrow = 2, ncol = 2)
plot_grid(
ggplot(meuse, aes(y = zinc, x = elev)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = elev)) + geom_point(),
nrow = 1, ncol = 2)
#3. Plot zinc against elevation and log zinc against elev
plot_grid(
ggplot(meuse, aes(y = zinc, x = dist)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = dist)) + geom_point(),
ggplot(meuse, aes(y = log(zinc), x = sqrt(dist))) + geom_point(),
nrow = 1, ncol = 3)
plot_grid(
ggplot(meuse, aes(y = log(zinc), x = ffreq)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = soil)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = lime)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = landuse)) + geom_boxplot(),
nrow = 2, ncol = 2)
#3. Plot representation of variation using the Boxplot
plot_grid(
ggplot(meuse, aes(y = log(zinc), x = ffreq)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = soil)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = lime)) + geom_boxplot(),
ggplot(meuse, aes(y = log(zinc), x = landuse)) + geom_boxplot(),
nrow = 2, ncol = 2)
#create a categorical variable
meuse$zinc_cat <-cut(meuse$zinc, breaks = c(0,200,400,800,1200,2000))
zinc.plot <- ggplot(aes(x=x, y=y), data = meuse)
zinc.plot<-zinc.plot+geom_point(aes(color = zinc_cat))
zinc.plot <- zinc.plot+coord_equal()
zinc.plot <- zinc.plot+scale_color_brewer(pallete = "YlGnBu")
# Spatial distribution of Zinc
zinc.plot
# Predict topsoil zinc concentration using spplot & bubble plots
spplot(meuse, "zinc", do.log = T, colorkey = TRUE)
bubble(meuse, "zinc", do.log = T, key.space = "right")
library(tidyr)
meuse=meuse %&gt;% drop_na() ## Remove NA variables
meuse=meuse %&gt;% drop_na() ## Remove NA variables
meuse=meuse drop_na() ## Remove NA variables
meuse=meuse, drop_na() ## Remove NA variables
#Experimental Variogram
plot(variogram(log(zinc)~1,meuse),type="h")
#Experimental Variogram
plot(variogram(log(zinc)~1,meuse),type="h")
ind <- sample(1:n, size=n, replace = F)
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$ffreq) <- paste("ffreq", levels(meuse$ffreq), sep="")
levels(meuse$soil) <- paste("soil", levels(meuse$soil), sep="")
str(meuse)
palette(trellis.par.get("superpose.symbol")$col)
plot(zinc~dist, meuse, pch=as.integer(ffreq), col=soil)
# Add lattice legend at the topright
legend("topright", col=c(rep(1, nlevels(meuse$ffreq)), 1:nlevels(meuse$soil)),
pch=c(1:nlevels(meuse$ffreq), rep(1, nlevels(meuse$soil))), bty="n",
legend=c(levels(meuse$ffreq), levels(meuse$soil)))
panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
}
xyplot(log(zinc)~dist | ffreq, meuse, groups=soil, panel=function(x, y, ...)
{
panel.xyplot(x, y, ...)
panel.loess(x, y, ...)
},
auto.key=TRUE)
# Distance to River
image(meuse.grid["dist"])
title("distance to river (red = 0)")
zinc.idw = idw(zinc~1, meuse, meuse.grid)
library(gstat)
zinc.idw = idw(zinc~1, meuse, meuse.grid)
#.------- STEP 3. View the spatial dataset on Meuse Map -- #
#1. Loading gridded data
data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
# Distance to River
image(meuse.grid["dist"])
spplot(zinc.idw["var1.pred"], main = "zinc inverse distance weighted interpolations")