我正在使用 r 中的克里金法进行插值。我想在它上面添加一张地图,但我不想留下任何空间。我正在使用automap
andggplot2
库,而光栅方法是autoKrige
.
# realization of the kriging method with the automap library
coordinates(dato1) = ~ X+Y
grad_ter_autokrig = autoKrige(GradTerm~1, dato1,)#diagrama de autokrige
str(grad_ter_autokrig)
#we convert the autokrige into a dataset to be read by ggplot
ggplot_data = as.data.frame(grad_ter_autokrig$krige_output)
str(ggplot_data)
#we make the outline of the map
contornokring<-data.frame(x=df$long,y=df$lat)
contornokring
plot(contornokring)
#We make the graph with raster its interpolation and with geom_polygon the polygon
ggplot(df, aes(x=long,y=lat)) +
geom_raster(data=ggplot_data, aes(x = x1, y = x2, fill = var1.pred),inherit.aes = FALSE) +
geom_polygon(data=df,aes(x=long,y=lat),fill=NA,
colour='black')