# NOT RUN {
# Loading Croatia data
data(croatia2008)
coordinates(croatia2008) <- ~x+y
# prediction case: one point
point <- data.frame(670863,5043464,5)
names(point) <- c("x","y","t")
coordinates(point) <- ~x+y
idwST(MTEMP~1, data=croatia2008, newdata=point, n.neigh=60, C=1, factor.p=2)
# }
# NOT RUN {
# prediction case: a grid of points Croatia (year 2008)
data(croatia)
points <- spsample(croatia, n=5000, type="regular")
data(croatia2008)
coordinates(croatia2008)<-~x+y
GridsT <- vector(mode = "list", length = 12)
for(i in 1:12){
GridsT[[i]] <- data.frame(points@coords,i)
names(GridsT[[i]]) <- c("x","y","t")
}
idw.croatia <- data.frame(matrix(NA, ncol = 14, nrow=nrow(GridsT[[1]])))
pb <- txtProgressBar(min = 0, max = 12, char = "=", style = 3)
for(i in 1:12){
coordinates(GridsT[[i]]) <- c("x", "y")
idw.croatia[,i+2] <- idwST(MTEMP~1, croatia2008, newdata=GridsT[[i]], n.neigh=10, C=1,
factor.p=2, progress=FALSE)[,4]
setTxtProgressBar(pb, i)
}
close(pb)
idw.croatia[,1:2] <- GridsT[[1]]@coords
nam <- paste(c("ENE","FEB","MAR","ABR","MAY","JUN","JUL","AGO","SEP","OCT","NOV","DIC"),
2008,sep="")
names(idw.croatia) <- c("x","y",nam)
coordinates(idw.croatia) <- c("x", "y")
gridded(idw.croatia) <- TRUE
# show prediction map
pal2 <- colorRampPalette(c("blue3", "wheat1", "red3"))
p1 <- spplot(idw.croatia[,1:12], cuts=30, col.regions=pal2(35), colorkey=F,
scales = list(draw =T,cex=0.6, abbreviate=TRUE,minlength=1), pch=0.3,
cex.lab=0.3, cex.title=0.3, auto.key = F, main = "Earth's average
temperature IDW map 2008", key.space=list(space="right", cex=0.8))
split.screen( rbind(c(0, 1,0,1), c(1,1,0,1)))
split.screen(c(1,2), screen=1)-> ind
screen( ind[1])
p1
screen( ind[2])
image.plot(legend.only=TRUE, legend.width=0.5, col=pal2(100),
smallplot=c(0.7,0.75, 0.3,0.7), zlim=c(min(idw.croatia@data),
max(idw.croatia@data)), axis.args = list(cex.axis = 0.7))
close.screen( all=TRUE)
# }
Run the code above in your browser using DataLab