我希望在将矩阵(temp_matrix)转换为栅格对象(tempMap)后绘制它的图表。此外,我希望在同一图表窗口中添加一些已知纬度和经度位置的点。我尝试了几种方法,但由于可用的点是特定的经纬度位置,而我得到的栅格对象具有不同的范围,因此没有一种方法能够奏效。请帮我解决这个问题。以下是该问题的示例数据。
library(raster)
temp_matrix<-array(NA,c(11,11))
temp_matrix[1,]<-c(NA,NA,NA,NA,NA,NA,NA,0,0,-6,-6)
temp_matrix[2,]<-c(0,0,0,0,NA,NA,1,0,0,0,0)
temp_matrix[3,]<-c(1,0,0,-1,-1,0,0,0,1,0,0)
temp_matrix[4,]<-c(1,1,0,0,0,0,-1,-1,0,0,0)
temp_matrix[5,]<-c(1,NA,NA,NA,NA,-1,-1,-1,0,-1,-1)
temp_matrix[6,]<-c(NA,NA,NA,NA,NA,NA,-1,-1,-1,0,0)
temp_matrix[7,]<-c(NA,NA,NA,NA,NA,NA,NA,0,-1,0,0)
temp_matrix[8,]<-c( NA,NA,NA,NA,NA,NA,NA,0,0,0,-1)
temp_matrix[9,]<-c(NA,NA,NA,NA,NA,NA,NA,-1,0,0,0)
temp_matrix[10,]<-c(NA,NA,NA,NA,NA,NA,NA,NA,-1,-1,-2)
temp_matrix[11,]<-c(NA,NA,NA,NA,NA,NA,NA,NA,-2,-3,-2)
plot(raster(temp_matrix),axes = FALSE,legend=FALSE)
tempMap <- raster(temp_matrix)
# plot the points over this raster layer
point_1<-c(10,10) # should appear on 2nd row from top i.e. over temp_matrix[2,10]
point_2<-c(9,10) # should appear on 3rd row from top i.e. over temp_matrix[3,10]
point_3<-c(1,10) # should appear on lowermost row i.e.over temp_matrix[11,10]
x
和y
弄反了。使用一些虚拟数据(一个称为m
的 37 行、72 列矩阵),raster(m,ymn=-14.5,ymx=22.5,xmn=-36,xmx=36)
会生成一个分辨率为1,1
的栅格。 - mnellibrary(fortunes);fortune(143)
。 - mnel