我一直在寻找一段时间,我能找到的唯一类似问题是(http://stackoverflow.com/questions/17722403/adding-land-boundary-to-a-filled-contour-plot)没有答案。 我已经在“光栅”中尝试了示例代码。文档没有问题(http://www.inside-r.org/packages/cran/raster/docs/plot)。但是,我自己的数据一直存在问题。虽然它可以很好地绘制光栅对象,但是我无法用“'线条”绘制线条。 (不得指向'点')。
我发现这与光栅的范围有关。这就是我尝试过的:
#Loading data
map.asc <- readGDAL("MDT05-1105-1108-H28-LIDAR.asc")
map.raster <- raster(map.asc)
rm(map.asc)
#Plotting. The x and y values are within the range of the extent
plot(map.raster)
lines(map.point.x, map.point.y, type = "l")
#It doesn't work
text(map.point.x,map.point.y,"Hello")
#IT WORKS!!!! Habemus text!!!!
#This is why I think it´s something with the extent. Here I´m trying to simulate
#the example of the documentation.
#A new raster with the same values but not the extent
other.raster <- raster(ncol = ncol(map.raster), nrow = nrow(map.raster))
other.raster <- setValues(other.raster, getValues(map.raster))
lines(other.point.x, other.point.y, type = "l")
#IT WORKS!!!! Habemus line!!!!
other.raster <- setExtent(other.raster, extent(map.raster))
lines(map.point.x, map.point.y, type = "l")
#It doesn't work
我也试过plot(..., add = TRUE)
但没有成功。
任何变通方法或建议将不胜感激。