R栅格图例标签未与间距对齐

时间:2016-03-31 16:15:10

标签: r plot legend raster legend-properties

这个让我发疯,我似乎无法磨练它。也许其他人有这个问题。我正在绘制一个光栅并分别绘制它的图例。图例轴标签不会与图例中的断点完全对齐,而是让我疯狂。下面是我调用的代码,以及所有输入变量,然后是正在发生的事情的屏幕截图。

传奇电话

plot(lzreate,
       col=qcol,
       legend.only=TRUE,
       legend.shrink=1,
       legend.width=2.5,
       breaks=ltq,
       axis.args=list(at=ltq,
                      labels=round(zp,2),
                      fg=txtcol,
                      col.axis=txtcol))

栅格对象

>lzreate

class       : RasterLayer 
dimensions  : 2647, 3900, 10323300  (nrow, ncol, ncell)
resolution  : 3333, 3333  (x, y)
extent      : -7332781, 5665919, -4372829, 4449622  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : -3.490627, 0.7254335  (min, max)

颜色

>length(qcol)
[1] 24
>qcol
 [1] "#0A0A0A" "#1F1209" "#341B08" "#492407" "#5F2D06" "#743605" "#893F04"
 [8] "#9F4803" "#B45103" "#C95A02" "#DF6301" "#F46C00" "#FF770B" "#FF8321"
[15] "#FF8F37" "#FF9C4D" "#FFA863" "#FFB479" "#FFC190" "#FFCDA6" "#FFD9BC"
[22] "#FFE6D2" "#FFF2E8" "#FFFFFF"

Zlim

>lzl
[1] -3.536184  1.896070

> length(ltq)
[1] 25
> ltq
 [1] -3.53618385 -2.70255423 -2.38880472 -2.07505520 -1.91818045 -1.76130569
 [7] -1.60443093 -1.44755617 -1.29068142 -1.13380666 -0.97693190 -0.89849452
[13] -0.82005714 -0.74161977 -0.66318239 -0.50630763 -0.34943287 -0.19255811
[19] -0.03568336  0.12119140  0.27806616  0.43494092  0.74869043  1.06243995
[25]  1.89606956

标签

> length(zp)
[1] 25
> round(zp,2)
 [1] 0.00 0.07 0.09 0.13 0.15 0.17 0.20 0.24 0.28 0.32 0.38 0.41 0.44 0.48 0.52
[16] 0.60 0.71 0.82 0.96 1.13 1.32 1.54 2.11 2.89 6.66

结果

enter image description here

1 个答案:

答案 0 :(得分:1)

fields::image.plot似乎做得更好,例如:

library(fields)
image.plot(lzreate, col=qcol, legend.only=TRUE,
           legend.width=2.5, breaks=ltq, lab.breaks=round(zp, 2))

enter image description here