How to remove the box frame in "plot.raster" in R package "raster"
Asked Answered
O

2

18

I need to remove the box frame around the figure in R package "raster", but I cannot figure out which argument I should change. The example is as follows:

library(raster)

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

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

plot(r)

plot(r,axes=F)
Obvolute answered 22/1, 2013 at 23:8 Comment(0)
V
37

This works:

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

To learn how you could have found that out for yourself, have a look at the underlying functions by trying the following. (The calls to showMethods() and getMethod() are needed because the raster package makes extensive use of S4 methods rather than the more commonly used S3 methods.)

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, ...) 
Vimen answered 22/1, 2013 at 23:39 Comment(3)
This is fantastic. ThanksPlayboy
@Playboy You bet. Glad it helped.Spay
plot(r,box=F) does not give error but still plots the box.Cassady
T
1

The best I can suggest is

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

The option bty='n' usually gets rid of the box, but the raster-plotting function seems to be drawing its own box on top of the regular box that you can't get rid of.

Triennium answered 22/1, 2013 at 23:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.