简体   繁体   中英

levelplot panel width and height R

How can I change the width and height of the plot below such that it becomes a square and aspect="fill" ?. There are 48 of such images in one plot so the images tend to be really flat when I export them using:

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

I have tried changing the aspect ratio but it won't resize the image. I prefer not to use Viewport due to its complexity.

The code for generating the map:

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

这是加拿大南部的地图

I found that one could control the aspect by using:

update(a1_1, aspect=0.5) # change value as necessary.

Using aspect=0.5 or "fill" etc within the levelplot call did not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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