[R] Map plotting in a box

Ray Brownrigg Ray.Brownrigg at ecs.vuw.ac.nz
Sat Mar 1 01:06:17 CET 2014


On 01/03/14 03:53, 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?
> Thanks in advance,Ciara 		 	   		  
> 	[[alternative HTML version deleted]]

Since your code is not reproducible (and not readable since it is in
HTML - see the posting guide), I can't comment further than saying that:

library(mapdata)
map("worldHires","Ireland")
box()

seems to me to do what you want, so are you using a different version of
box()?  If it is not what you want. you need to be more explicit.

Ray Brownrigg



More information about the R-help mailing list