Legend properties when legend.only=T (raster package)

后端 未结 2 1710
星月不相逢
星月不相逢 2021-01-31 04:30

When plotting only the legend (of a raster object - a colorbar):

require(raster)
r = raster()
r[] = 1
plot(r, legend=F)
plot(r, zlim=c(-10,10), lege         


        
相关标签:
2条回答
  • 2021-01-31 05:07

    It's also possible to work with the 'smallplot' argument in when 'legend.only=TRUE'. Small works from the bottom/left corner of the plot area smallplot=c(min % from left, max % from left, min % from bottom, max % from bottom).

    # load data & plot
    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=1, legend.shrink=0.75,
        smallplot=c(0,.09, .3,.75)); par(mar = par("mar"))
    
    plot(r, legend.only=TRUE, col=topo.colors(100), legend.width=1, legend.shrink=0.75,
        smallplot=c(0.3,0.5, 0.2,0.7)); par(mar = par("mar"))
    
    plot(r, legend.only=TRUE, col=topo.colors(100), legend.width=1, legend.shrink=0.75,
        smallplot=c(0.85,0.9, 0.7,0.9)); par(mar = par("mar"))
    
    plot(r, legend.only=TRUE, col=topo.colors(100), legend.width=1, legend.shrink=0.75,
        smallplot=c(0.7,0.90, 0.05,0.2)); par(mar = par("mar"))
    

    0 讨论(0)
  • 2021-01-31 05:10

    You can pass axis.args and legend.args as arguments to the legend only function call, as for image.plot in the fields package.

    For example, to specify tick positions and labels, and to reduce tick label size, the following should do the trick. It will also accept arguments such as legend.width and legend.shrink.

    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=1, legend.shrink=0.75,
         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))
    

    legend only - arguments

    0 讨论(0)
提交回复
热议问题