【发布时间】:2014-10-09 02:01:53
【问题描述】:
使用了两个数据集:
3 列中的空间数据(x、y、数据)
2 列 (x, y) 中的网格数据
automap 包 autoKrige 进行克里金的计算,可以在没有 x 和 y 刻度线和标签的情况下绘制:
plot(kriging_result)
automapPlot(kriging_result$krige_output, "var1.pred", sp.layout = list("sp.points", shimadata), main="OK without grids", xlab="x", ylab="y")
当我使用 ggplot2 包时,它会显示错误,但是它会计算克里金法:
mydata<-read.table("D:/.../mydata.txt",header=T,sep=",")
#Renaming desired columns:
x<-mydata[,1]
y<-mydata[,2]
waterelev<-mydata[,3]
library(gstat)
coordinates(mydata)=~x+y
library(ggplot2)
theme_set(theme_bw())
library(scales)
library(automap)
grids<-read.table("D:/.../grids.txt",header=T,sep=",")
gridded(grids)=~x+y
kriging_result = autoKrige(log(waterelev)~1, mydata)
#This line turns the log(data) back to the original data:
kriging_result$krige_output$var1.pred<-exp(kriging_result$krige_output$var1.pred)
library(reshape2)
ggplot_data = as.data.frame(kriging_result$krige_output)
ggplot(ggplot_data, aes(x = x, y = y, fill = var1.pred)) +
geom_raster() + coord_fixed() +
scale_fill_gradient(low = 'white', high = muted('blue'))
错误:
错误:美学长度必须为 1,或与 dataProblems:x,y 长度相同
【问题讨论】: