2

How do I remove the black box surrounding the raster legend? More generally, where can I find the documentation for the options for R raster legends?

   require(raster)
        data(volcano)
        r <- raster(volcano)
        plot(r, col=topo.colors(100), legend=FALSE, axes=FALSE)
        r.range <- c(minValue(r), maxValue(r))
        plot(r, legend.only=TRUE, col=topo.colors(100),
             legend.width = 2,
             axis.args=list(at=seq(r.range[1], r.range[2], 25),
                            labels=seq(r.range[1], r.range[2], 25), 
                            cex.axis=0.6),
             legend.args=list(text='Elevation (m)', side=4, font=2, line=2.5, cex=0.8))
ZAC
  • 97
  • 1
  • 6

1 Answers1

2

You can use par(bty='n') before ploting the legend:

par(bty= "n") # remove the box
plot(r, legend.only=TRUE, col=topo.colors(100),
     legend.width = 2,
     axis.args=list(at=seq(r.range[1], r.range[2], 25),
                    labels=seq(r.range[1], r.range[2], 25), 
                    cex.axis=0.6),
     legend.args=list(text='Elevation (m)', side=4, font=2, line=2.5, cex=0.8))
par(bty= "o") # set the box

enter image description here

HubertL
  • 19,246
  • 3
  • 32
  • 51
  • Thanks! Do you have any advice for finding fixes such as these more generally? I searched the documentation for the plot raster legend and obviously this fix is separate from that. – ZAC Jun 09 '16 at 07:10
  • 1
    Usually, specific `plot()` documentation only describe their specific part, so for plotting options that are generic (not specific to raster) you have to look at generic `plot()` documentation (`?plot` then select base R ) – HubertL Jun 09 '16 at 18:39