【问题标题】:How to remove the box frame in "plot.raster" in R package "raster"如何删除 R 包“raster”中“plot.raster”中的框框
【发布时间】:2013-01-06 08:15:48
【问题描述】:

我需要删除 R 包“raster”中图形周围的框框,但我不知道应该更改哪个参数。示例如下:

library(raster)

r <- raster(nrows=10, ncols=10)

r <- setValues(r, 1:ncell(r))

plot(r)

plot(r,axes=F)

【问题讨论】:

    标签: r plot spatial raster


    【解决方案1】:

    这行得通:

    plot(r, axes=FALSE, box=FALSE)
    

    要了解您自己是如何发现这一点的,请尝试以下方法来查看底层函数。 (需要调用showMethods()getMethod(),因为raster 包大量使用了S4 方法,而不是更常用的S3 方法。)

    showMethods("plot")
    getMethod("plot", c("Raster", "ANY"))
    getAnywhere(".plotraster2")
    getAnywhere(".rasterImagePlot")
    args(raster:::.rasterImagePlot)
    # function (x, col, add = FALSE, legend = TRUE, horizontal = FALSE, 
    #     legend.shrink = 0.5, legend.width = 0.6, legend.mar = ifelse(horizontal, 
    #         3.1, 5.1), legend.lab = NULL, graphics.reset = FALSE, 
    #     bigplot = NULL, smallplot = NULL, legend.only = FALSE, lab.breaks = NULL, 
    #     axis.args = NULL, legend.args = NULL, interpolate = FALSE, 
    #     box = TRUE, breaks = NULL, zlim = NULL, zlimcol = NULL, fun = NULL, 
    #     asp, colNA = NA, ...) 
    

    【讨论】:

    • 这太棒了。谢谢
    • @gonzalez.ivan90 你打赌。很高兴它有帮助。
    【解决方案2】:

    我能建议的最好的是

    plot(r,axes=F,useRaster=F)
    

    bty='n' 选项通常会去掉方框,但光栅绘图功能似乎是在无法去掉的常规方框上绘制自己的方框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-03
      • 2016-04-09
      • 1970-01-01
      • 2017-08-06
      • 2020-11-22
      • 2012-11-13
      • 2011-11-24
      相关资源
      最近更新 更多