Search code examples
rlegendr-rasterlegend-properties

Legend Options - R Raster Legend


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))

Solution

  • 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