ExH*_*ter 5 plot r raster shapefile
我正在 R 中绘制栅格数据,当我调整到我正在处理的区域时,R 显示不想被切断的 ylim。
我试过:
# set lon lat
ylim=c(-4,2)
xlim=c(118,126)
plot(pm10_mean,xlim=xlim, ylim=ylim)
plot(shp, add=TRUE)
plot(shp2, add=TRUE)
Run Code Online (Sandbox Code Playgroud)
但我得到了这样的照片
如何删除 2 以上和 -4 以下的可用空间?我只想在xlim和中绘制区域ylim
我以前也遇到过这个问题。您可以手动调整绘图区域的大小以删除空白区域,或插入多边形以覆盖 shapefile 中不需要的区域。但最安全的选择是使用,spplot因为这会自动为您调整绘图区域的大小:
require(maptoolS)
require(raster)
data(wrld_simpl)
rs=raster()
rs[]=1
id_shp=wrld_simpl[which(wrld_simpl$ISO2=="ID"),]
rs=crop(rs,id_shp)
rs=disaggregate(rs,40)
rs=mask(rs,id_shp)
spplot(rs,ylim=c(-4,2),xlim=c(118,126),sp.layout=list('sp.lines', id_shp, lwd=2,first=F))
Run Code Online (Sandbox Code Playgroud)