-->

如何插入x和y标签和autoKrige刻度线?(how to insert x and y labe

2019-10-20 17:28发布

两个数据集用于:

  1. 在3列空间数据(X,Y,数据)

  2. 在2列网格数据(x,y)的

自动地图包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'))

错误:

错误:美学必须是长度的一个或相同的长度dataProblems:X,Y

Answer 1:

我用你提供的数据集,而我像后的图像结果:

我只是运行你的代码,直到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)

这是你的预期?



Answer 2:

automapPlot函数是一个包装spplot ,这样对于任何工程修复spplot也将适用于automapPlot 。 你可以用开始spplot对于一个地方开始文档。

然而,我通常使用的ggplot2包任何绘图工作,包括空间数据。 以下是其再现automapPlot的结果的一个例子:

library(ggplot2)
theme_set(theme_bw())
library(scales)
library(automap)
data(meuse)
coordinates(meuse) =~ x+y
data(meuse.grid)
gridded(meuse.grid) =~ x+y
kriging_result = autoKrige(zinc~1, meuse, meuse.grid)

# Cast the Spatial object to a data.frame
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'))



文章来源: how to insert x and y label and tick marks in autoKrige?
标签: r label automap