[R] Map plotting in a box

Jim Lemon jim at bitwrit.com.au
Sat Mar 1 04:19:19 CET 2014


On 03/01/2014 01:53 AM, Ciara O'Hara wrote:
> Hi everyone,
> I am using the script below to create a map plot of Ireland.
> library(ncdf)library(maps)library(mapdata)library(maptools)library(RColorBrewer)shapefile<-readShapeLines("C:\\Users\\sophysics\\Desktop\\IRL_adm\\IRL_adm1.shp")file<-open.ncdf("C:\\Users\\sophysics\\Desktop\\TempData\\average\\average_1961.nc")data<-get.var.ncdf(file,"var61")lat<-get.var.ncdf(file,"lat")lon<-get.var.ncdf(file,"lon")map("worldHires","Ireland",col="purple",fill=FALSE,box=NULL)image(lon,lat,data,col="purple",xaxt="n",yaxt="n",ann=FALSE,box=NULL,xlab=NULL,ylab=NULL,asp=-1)plot(shapefile,add=TRUE,border=FALSE)
> I want to get that box around to fit snugly around the coastline, but I can't figure out how to do this. The box("inner") command doesn't seem to be doing anything for me, and box("outer"), box("figure") create boxes outside. I've tried various combinations of the par(mar) and par(omi/oma) commands, but these refer to the boxes outside the inner plot.
> Is it possible to make the map fit snugly inside a box?

Hi Ciara,
As I don't have the map data that you used, I can only suggest that you 
try fiddling with the xlim and ylim arguments to get as little space 
around Ireland as you can. Add axes to your original plot to see roughly 
where these limits would be.

Jim




More information about the R-help mailing list