简体   繁体   English

legend.only = T(光栅包)时的图例属性

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

When plotting only the legend (of a raster object - a colorbar): 仅绘制图例( raster对象 - 颜色条)时:

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

how can I control the legend axis label size, tick length, and other legend properties? 如何控制图例轴标签大小,刻度线长度和其他图例属性? I know I can call par(...) before the last plot() call, but is there a cleaner way? 我知道我可以在最后一个plot()调用之前调用par(...) ,但有更简洁的方法吗?

You can pass axis.args and legend.args as arguments to the legend only function call, as for image.plot in the fields package. 您可以将axis.argslegend.args作为参数传递给仅图例函数调用, 就像 fields包中的image.plot

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 . 它还将接受诸如legend.widthlegend.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))

仅限传说 - 参数

It's also possible to work with the 'smallplot' argument in when 'legend.only=TRUE'. 当'legend.only = TRUE'时,也可以使用'smallplot'参数。 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). 从小区的左下角开始的小作品smallplot = c(左起最小%,左起最大%,底部最小%,底部最大%)。

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

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM