如何在autoKrige中插入x和y标签和刻度线? [英] how to insert x and y label and tick marks in autoKrige?
问题描述
使用了两个数据集:
-
3列(x,y,数据)中的空间数据
spatial data in 3 columns (x, y, data)
将数据分为2列(x,y)
grids data in 2 columns (x, y)
automap程序包autoKrige进行kriging的计算,并且可以在不带有x和y刻度线和标签的情况下进行绘制:
automap package autoKrige does the calculation of kriging and can be plotted with no x and y tick marks and labels:
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:
And when I use ggplot2 package, it shows error, however it calculates the 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,或者与dataProblems:x,y的长度相同
Error: Aesthetics must either be length one, or the same length as the dataProblems:x, y
推荐答案
我使用了您提供的数据集,并且将结果发布为图像:
I used the dataset you provided, and, I post the result like an image:
我只是运行您的代码,直到生成ggplot_data为止,将其从spPointsDataFrame(网格)转换为data.frame(带有reshape2). 然后我逐步构建了ggplot对象,但没有发现错误:
I just run your code until ggplot_data is produced casting from an spPointsDataFrame (gridded), to a data.frame (with reshape2). Then I built the ggplot object step by step but I found no errors:
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)
这是您期望的吗?
这篇关于如何在autoKrige中插入x和y标签和刻度线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!