我有在美国切萨皮克湾不同地点采集的物种丰富度调查数据,我想以图形方式将这些数据呈现为“热图”。
我有一个纬度/经度坐标和丰富度值的数据框,我将其转换为SpatialPointsDataFrame
并使用了autoKrige()
automap 包中的函数用于生成插值。
首先,任何人都可以评论我是否正确实施了autoKrige()
功能?
其次,我在绘制数据和覆盖该地区的地图时遇到困难。或者,我可以指定插值网格来反映海湾的边界(如建议的那样)here https://stackoverflow.com/questions/8563334/average-values-of-a-point-dataset-to-a-grid-dataset)?关于如何做到这一点以及从哪里可以获得这些信息有什么想法吗?向电网供电autoKrige()
看起来很容易。
编辑:感谢保罗的超级有用的帖子!这是我现在所拥有的。让 ggplot 接受插值数据和地图投影时遇到问题:
require(rgdal)
require(automap)
#Generate lat/long coordinates and richness data
set.seed(6)
df=data.frame(
lat=sample(seq(36.9,39.3,by=0.01),100,rep=T),
long=sample(seq(-76.5,-76,by=0.01),100,rep=T),
fd=runif(10,0,10))
initial.df=df
#Convert dataframe into SpatialPointsDataFrame
coordinates(df)=~long+lat
#Project latlong coordinates onto an ellipse
proj4string(df)="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
#+proj = the type of projection (lat/long)
#+ellps and +datum = the irregularity in the ellipse represented by planet earth
#Transform the projection into Euclidean distances
project_df=spTransform(df, CRS("+proj=merc +zone=18s +ellps=WGS84 +datum=WGS84")) #projInfo(type="proj")
#Perform the interpolation using kriging
kr=autoKrige(fd~1,project_df)
#Extract the output and convert to dataframe for easy plotting with ggplot2
kr.output=as.data.frame(kr$krige_output)
#Plot the output
#Load the map data for the Chesapeake Bay
cb=data.frame(map("state",xlim=range(initial.df$long),ylim=range(initial.df$lat),plot=F)[c("x","y")])
ggplot()+
geom_tile(data=kr.output,aes(x=x1,y=x2,fill=var1.pred))+
geom_path(data=cb,aes(x=x,y=y))+
coord_map(projection="mercator")