文本未添加到光栅图中

text not being added to raster plot

我正在绘制这样的光栅:

library(raster)

raster = raster("C:\Pathway\raster.tif")

plot(raster)
text(0.4, 0.8, "text")

但是我的文本没有被添加。当我在 raster 包中使用预加载的栅格时,它可以工作。例如:

plot(raster(volcano))
text(0.4, 0.8, "text")

我的文字已添加。

您确定点 c(0.4, 0.8) 包含(*)在您的栅格范围内吗?当你第一次绘制光栅时,这会设置绘图区域的限制,如果你的文本坐标不属于它们,它就不会出现...

(*) 或不太远

library(raster)

r = raster(volcano)

par(mfrow=c(3,1))

plot(r)
text(0.4, 0.8, "text")

extent(r) = c(1,2,1,2) #Change the extent --> c(0.4,0.8) is quite far away
plot(r)
text(0.4, 0.8, "text") # does NOT appear...

plot(r)
text(1.4, 1.8, "text") # Back in the plot region --> does indeed appear
text(0.8, 1.5, "Close enough") # Does also appear...