【问题标题】:Adding text labels to a raster plot向光栅图添加文本标签
【发布时间】:2013-07-09 22:18:26
【问题描述】:

脚本:

library(raster)
places = data.frame(x=c(0.2, 0.7), y=c(0.2, 0.7), name=c('A','B'), stringsAsFactors=F)
plot(raster(volcano))
points(places$x, places$y, pch=16)
text(places$name, places$x, places$y-0.1)

在最后一行失败并显示消息:In xy.coords(x, y, recycle = TRUE) : NAs introduced by coercion。我认为这是由于混合了图形库,但光栅中的text 函数似乎只适用于光栅格式的文本对象。感谢有关如何在栅格图上添加离散点的建议。

【问题讨论】:

    标签: r raster


    【解决方案1】:

    您可以正常使用 graphics::text,但它需要 x、y 作为第一个参数,就像 points 和许多其他 xy.coords 函数一样:

    text(x = places$x, y = places$y-0.1, labels = places$name)
    

    【讨论】:

      猜你喜欢
      • 2011-04-15
      • 1970-01-01
      • 2018-11-27
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      • 2017-06-01
      相关资源
      最近更新 更多