두 개의 데이터 세트가 사용됩니다.
3 개 열의 공간 데이터 (x, y, 데이터)
2 개 열 (x, y)의 그리드 데이터
automap 패키지 autoKrige는 kriging 계산을 수행하며 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 패키지를 사용하면 오류가 표시되지만 kriging을 계산합니다.
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이거나 데이터와 길이가 같아야합니다. 문제 : x, y
제공 한 데이터 세트를 사용했으며 결과를 이미지처럼 게시합니다.
ggplot_data가 spPointsDataFrame (격자 표시)에서 data.frame (reshape2 사용)으로 캐스팅 될 때까지 코드를 실행합니다. 그런 다음 ggplot 개체를 단계별로 빌드했지만 오류가 발견되지 않았습니다.
g=ggplot(data=ggplot_data,aes(x=x1,y=x2,fill=var1.pred))
g=g+geom_raster()
g=g+coord_fixed()
g=g+scale_fill_gradient(low = 'white', high = muted('blue'))
print(g)
이것이 당신이 기대했던 것입니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다