2017-05-30 58 views
0

如何更改下面阴谋的widthheight,使其成为square和?。有这样的图像的48积于一身,因此图像往往是真的很平淡,当我使用它们导出:电平面板的宽度和高度R

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

+0

我调整rstudio中的绘图窗口大小并将它们导出为pdf。 –

+0

@ Geo-sp如果您在1个图表上显示> 2个水平图表的示例以及如何调整它们的大小,我将不胜感激。谢谢。 – code123

+0

如果您使用Rstudio,请尝试根据需要调整绘图窗口大小,然后使用导出,然后另存为pdf。我发现这是写情节最方便的方式。我通常使用Photoshop将PDF文件转换为tiff格式。我希望这有帮助。 –

回答

1

我发现有一个可以通过使用控制方面:

update(a1_1, aspect=0.5)#变化值是必要的。

使用aspect=0.5 or "fill"levelplot调用不起作用。