I would like to mask the ocean in a map of a section of Australia.
Here is my starting point:
library(maps)
library(mapdata)
image(x=110:155, y =-40:-10, z = outer(1:45, 1:30, "+"),
xlab = "lon", ylab = "lat")
Then, following the solution posted here (How can I color the ocean blue in a map of the US?) I set up the polypath:
outline <- map("worldHires", plot=FALSE) # returns a list of x/y coords
xrange <- range(outline$x, na.rm=TRUE) # get bounding box
yrange <- range(outline$y, na.rm=TRUE)
xbox <- xrange + c(-2, 2)
ybox <- yrange + c(-2, 2)
# create the grid path in the current device
polypath(c(outline$x, NA, c(xbox, rev(xbox))),
c(outline$y, NA, rep(ybox, each=2)),
col="light blue", rule="evenodd")][1]
However the resultant plot is masked either side of the country border. Can anyone help me only mask outside the country borders?