Note that there are some explanatory texts on larger screens.

plurals
  1. POR crop raster data and set axis limits
    primarykey
    data
    text
    <p>With your help in another thread I have managed to plot some global maps. First I convert meteorological GRIB2 data to Netcdf and then plot the global maps. </p> <p>Now I want to plot just a subregion of the map. I have tried crop command and succesfully extracted the subregion of the global nc file. But when plotting I can't find how to control axis limits. It plots a map bigger than data region so big white spaces appear on both sides.</p> <p>This is the script I'm using to plot maps</p> <pre><code>library("ncdf") library("raster") library("maptools") DIA=format(Sys.time(), "%Y%m%d00") # Data d'avui url=sprintf("ftp://ftp.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.%s/gfs.t00z.pgrb2f00", DIA) # Ruta del ftp loc=file.path(sprintf("%s",url)) download.file(loc,"gfs.grb",mode="wb") system("/usr/bin/grib2/wgrib2/wgrib2 -s gfs.grb | grep :TMP: | /usr/bin/grib2/wgrib2/wgrib2 -i gfs.grb -netcdf temp.nc",intern=T) t2m &lt;- raster("temp.nc", varname = "TMP_2maboveground") rt2m &lt;- rotate(t2m) t2mc=rt2m-273.15 DAY=format(Sys.time(), "%Y%m%d") # Data d'avui e=extent(-40,40,20,90) tt=crop(t2mc,e) png(filename="gfs.png",width=700,height=600,bg="white") rgb.palette &lt;- colorRampPalette(c("snow1","snow2","snow3","seagreen","orange","firebrick"), space = "rgb")#colors plot(tt,col=rgb.palette(200),main=as.expression(paste("Temperatura a 2m ",DAY," + 00 UTC",sep="")),axes=T) dev.off() </code></pre> <p>that give this output.</p> <p><img src="https://i.stack.imgur.com/DOyZr.png" alt="cropped plot"></p> <p>It has to be a simple one but I am a simple R user. Thanks in advance.</p> <p>EDIT: New output when adding xlim=c(-40,40),ylim=c(20,90) as suggested. It seems it does not fix the problem. But playing with x,y size of the output png file looks promising as I can adjust size to fit the map.For sure it has to be another solution, the right one I can't find.</p> <p><img src="https://i.stack.imgur.com/xsh9Y.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload