I would load your data into a raster stack from the raster
package and then use the merge
and crop
functions. Basically you duplicate the raster, shift it 360 degrees, then merge that with itself, then crop it to taste. Here's a function:
require(raster)
wwrap <- function(g,xmax=720){
gE = extent(g)
shiftE = extent(360,720,gE@ymin, gE@ymax)
g2 = g
extent(g2)=shiftE
gMerge = merge(g,g2)
crop(gMerge,extent(0,xmax,gE@ymin, gE@ymax))
}
And here's some usage:
> gstack = stack("foo.grb")
> gstack[gstack>100] = NA
> gstack2 = wwrap(gstack,xmax=460)
> plot(gstack2)
> plot(gstack2[[1]])
> plot(gstack2[[61]])
Probably more efficient to shift and crop the raster first, then merge, but this is a start and it only takes a few seconds to run on your raster.
If all you care about is plotting then it might be easier to write a function that plots it twice, once with a shift in extent. But that would have to be done for each band in your raster....
wraplot <- function(g,xmax=720){
gE = extent(g)
## to setup the plot
worldWrap = extent(0,xmax,gE@ymin, gE@ymax)
rWrap = raster(nrows=1,ncols=1,ext=worldWrap)
rWrap[]=NA
plot(rWrap)
## first part
plot(g,add=TRUE)
## setup and plot it again
shiftE = extent(360,720,gE@ymin, gE@ymax)
cropE = extent(360,xmax,gE@ymin, gE@ymax)
extent(g)=shiftE
g=crop(g,cropE)
plot(g,add=TRUE)
}
Then you do:
wraplot(gstack[[1]])
Check out all the features of the raster
package.