如何更改下图的width和height,使其成为square和aspect="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

发布于 2017-06-03 00:25:54
我发现可以通过使用以下命令来控制方面:
update(a1_1, aspect=0.5)#根据需要更改值。
在levelplot调用中使用aspect=0.5 or "fill"等不起作用。
https://stackoverflow.com/questions/44273214
复制相似问题