Indeed, this is pretty much what the rotate function in the raster package
does (except it only goes from 0-360 to -180-180, and not the other way).

You could just get the code from this simple function and reverse it:

library(raster)
getMethod('rotate', 'Raster')

M


On Wed, Feb 27, 2013 at 9:56 AM, Alexandre Castagna <
alexandre.castagna@gmail.com> wrote:

> Sophie,
>
> There is probably a better way to do this, but you can manipulate the
> raster as a matrix and exchange row's orders. If your data spans the 360º
> longitude, is just the case to take the first half of the rows and replace
> them after the second half of the rows.
>
> An example could be:
>
> X = # your raster object #
>
> Original.Extent = extent(X)
> Values = t(as.matrix(X))
> New.Values.1 = Values[1:(ncol(X)/2),]
> New.Values.2 = Values[((ncol(X)/2)+1):ncol(X),]
> New.Values = rbind(New.Values.2,New.Values.1)
> Values(X) = as.vector(New.Values)
> extent(X) = extent(Original.Extent@xmin+180,Original.Extent@xmax+180
> ,Original.Extent@ymin,Original.Extent@ymax)
>
>
> 2013/2/27 Sophie MONSARRAT <Sophie.MONSARRAT@cefe.cnrs.fr>
>
> > Hello all,
> >
> > I am currently working with environmental data at a global scale for
> > modeling marine species distribution. These environmental data are
> provided
> > as ASCII files and I convert them into raster for the analyzes, using the
> > raster package.
> >
> > All of these raster are centered around the Greenwich meridian. However,
> > for visualization purpose, I would like to be able to plot these raster
> > centering them on the Pacific.
> >
> > This is easily done with GIS software, by defining the central meridian
> at
> > -180° in the coordinate system. However, I can't find a way to do the
> same
> > in R. I tried to adjust the coordinate reference system as follows:
> >
> > SST.ras <- raster(SST.asc,crs = "+proj=merc  +lat_ts=0 +lon_0=-180 +x_0=0
> > +y_0=0 +ellps=WGS84 +over")
> >
> > But this has no effect on the way the raster is plotted.
> >
> > The answer may be straightforward, but I didn't find any solution in
> other
> > topics. Can someone enlighten me on this?
> >
> > Thank you,
> > Sophie
> >
> >         [[alternative HTML version deleted]]
> >
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> >
>
>
> --
> Alexandre Castagna Mourão e Lima
> Laboratório de Radioecologia e Mudanças Globais - UERJ
> Rua São Francisco Xavier, 524, Maracanã
> Pav. Haroldo Lisboa da Cunha, Sub-solo
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Matthew Landis, Ph.D.
Research Scientist
ISciences, LLC
61 Main St., Suite 200
Burlington VT 05401

802-864-2999
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	[[alternative HTML version deleted]]

