levelplot面板宽度和高度R

时间:2017-05-30 23:02:09

标签: r maps raster levelplot

如何更改下方图表的widthheight,使其成为squareaspect="fill"?在一个图中有48个这样的图像,因此当我使用以下方法导出图像时,图像往往非常平坦:

library(Cairo)
Cairo(file="image.png",type="png",units="in", width=10, height=10, pointsize=12,dpi=1000)

我尝试更改宽高比但不会调整图像大小。由于其复杂性,我不想使用Viewport

生成地图的代码:

img:
class       : RasterLayer 
dimensions  : 232, 1061, 246152  (nrow, ncol, ncell)
resolution  : 0.08333333, 0.08333333  (x, y)
extent      : -141, -52.58334, 41.66667, 61  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0 
data source : in memory
names       : Dim.1 
values      : -0.251515, 0.7663837  (min, max)


require(colorRamps)
col=colorRampPalette(matlab.like2(255))
#col=colorRampPalette(rev(brewer.pal(11,"Spectral")))# don't use (100) or any other at end of this commenad else it wont work

color_levels=20 #the number of colors to use
max_abolute_value=1 #what is the maximum absolute value of raster?
color_sequence=unique(round(seq(-max_abolute_value,max_abolute_value,length.out=color_levels+1),3))
color_sequence

myColorkey <- list(at=color_sequence,space = "bottom", tck = c(0,0),
                   labels=list(axis.line = list(col = NA),at=color_sequence,rot=0,cex=0.9,font=6,fontface=1,
                               labels =c("-1.0", "", "-0.8", "", "-0.6", "", "-0.4", "", "-0.2", "",  
                                         "0.0",  "",  "0.2",  "",  "0.4",  "",  "0.6",  "",  "0.8", "",  "1.0")),height=0.92,width=1.6)

a1_1=levelplot(img,at = color_sequence,margin=F,col.regions=col,contour=F, panel = panel.levelplot.raster,
               par.strip.text=list(cex=0),colorkey =myColorkey,xlim=c(-141, -52.58334),
               ylim=c(41.66667, 62.16666),
               par.settings=list(panel.background=list(col="white"),aspect="fill",axis.line=list(lwd=1.1), strip.border=list(lwd=1.1),
                                 layout.heights=list(xlab.key.padding=-1.5)),
               cex=0.8, scales = list(x=list(draw=FALSE), y=list(draw=FALSE)),
               xlab=list(label=NULL,cex=1.5),
               ylab=list(label=NULL,cex=1.5))+layer(sp.polygons(Prairie.Boundaries,lwd=0.5,col="black"))# problem with n_in_class

It is a map of southern Canada

1 个答案:

答案 0 :(得分:2)

我发现可以使用以下方法控制方面:

update(a1_1, aspect=0.5)#根据需要更改值。

aspect=0.5 or "fill"电话中使用levelplot等无效。