Re: [R-sig-Geo] Help on pointLabel() function for engineering drawings

2015-09-27 Thread Oscar Perpiñán Lamigueiro
> Will using the lineLabel function align the labels as per the
> orientation of the line?

Yes, exactly.

> Also, I changed the lines to points and then tried the pointLabel
> function.  However, it ignores all the points that are not mentioned
> in the argument of the function and still plots over them. Any
> workaround for this?

You may include empty characters ("") as elements in the _labels_
vector. For example:

x <- 1:5
y <- 1:5
labels <- c('A', 'B', '', 'D', '')
plot(x, y)
pointLabel(x, y, labels)

Best.

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ing. Eléctrica, Electrónica, Automática y Física Aplicada
Escuela Técnica Superior de Ingeniería y Diseño Industrial
URL: http://oscarperpinan.github.io

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Help on pointLabel() function for engineering drawings

2015-09-26 Thread Oscar Perpiñán Lamigueiro
Hi,

You could try the `lineLabel` and `sp.lineLabel` functions of this same
package.

Best.

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ing. Eléctrica, Electrónica, Automática y Física Aplicada
Escuela Técnica Superior de Ingeniería y Diseño Industrial
URL: http://oscarperpinan.github.io

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] adding text to levelplot panels with rasterVis and level(panel.text(...))

2015-06-15 Thread Oscar Perpiñán Lamigueiro
Hi,

I think this is what you are looking for:

levelplot(s) +
layer(panel.text(179500, 333000,
 text2add[panel.number()]))

Best,

Oscar.

Oscar Perpiñán Lamigueiro
Dpto. Ing. Eléctrica, Electrónica, Automática y Física Aplicada
(ETSIDI-UPM) Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://oscarperpinan.github.io

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Multiple legends with levelplot and spplot

2014-10-20 Thread Oscar Perpiñán Lamigueiro
Hello,

You could try to define the legend for the Spatial* object inside the
levelplot call using the `key` argument. For example:

library(sp)
library(raster)
library(rasterVis)

f - system.file(external/test.grd, package=raster)
r - raster(f)

data(meuse)
coordinates(meuse) = c(x, y)
meuse$class - cut(meuse$zinc, 3)

ptsCols - c('black', 'red', 'blue')

lvp - levelplot(r, margin = FALSE,
 ## Define the legend for the spplot graphic
 key = list(space = 'top', text = list(levels(meuse$class)),
 points = list(pch = 21, fill = ptsCols)),
 ## Legend for the Raster object
 colorkey=list(space=right,width=0.75,height=0.75))

spp - spplot(meuse[class], col.regions = ptsCols)

lvp + spp


Best,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://oscarperpinan.github.io

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Order raster images in a levelplot

2014-10-20 Thread Oscar Perpiñán Lamigueiro
Hi,

 1. Does someone have any suggestions on how i can order the sequence
 of images in a “levelplot made using rasterVis.  Specifically, i
 have months i need to arrange in the normal sequence, as the plot
 currently aligns them in an alphabetical order. Does “levelplot”
 works the same way as xyplots in lattice?

levelplot methods defined in rasterVis are based on lattice graphics. 
Most of the arguments provided by lattice::xyplot and
lattice::levelplot are also available. For this issue you could try
these arguments: perm.cond, index.cond, as.table. All of them are
described in the help page of lattice::xyplot.

 2. Have there been more developments on the zApply function in the
 raster package? I am trying to make basic statistical summaries for
 mean monthly (eg. NDVI values) form a multi annual time series.  How
 does one go about using the “by Indexing in this case.

Could you post a reproducible example? I have used zApply for similar
tasks without problems.

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://oscarperpinan.github.io

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Select and plot specific row in rasterstack

2013-11-11 Thread Oscar Perpiñán Lamigueiro
Hello,

You can extract a row from a RasterStack with s[i,]. Try this code:
 
library(raster)
library(zoo)
library(lattice)

r - raster(nrow=20, ncol=5)
s - stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
## assign a time index to the 'RasterStack'
s - setZ(s, seq(Sys.Date()-4, by='day', length=5))

## extract a row (10) and convert the result (a 'matrix') into a 'zoo'
## object using the time index of the 'RasterStack' object
zz - zoo(t(s[10,]), order.by=getZ(s))

xyplot(zz, superpose=TRUE)


Best,

Oscar.
Eddie Smith writes:

 Dear list,

 How do I plot a specific row over time? For example I want to plot row
 10(layer.1 to 5 is actually year 1 to year 5.

 library(raster)
 r - raster(nrow=5, ncol=5)
 s - stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
 s[]

  layer.1layer.2 layer.3layer.4layer.5
  [1,]  6.7134890  6.9141251  4.38213123  4.8995302  2.3105321
  [2,]  3.4323121  6.1074031 10.12872426  3.6728949  3.2252562
  [3,]  4.4370107  3.1397068  5.47572912  1.9692684  4.0064603
  [4,] -1.5588723  0.4075960 -0.7754  6.3589944  5.0355051
  [5,]  2.8095750  5.4264553  1.17820009  2.0665198  8.0491221
  [6,]  4.3422219  2.1106691  1.08638206  5.0640175  6.8057674
  [7,] -3.1072366 -1.1174633  6.28901706  5.0713964  1.8651354
  [8,] -0.5628539  2.1868130  1.21288191  0.3114011  3.0452161
  [9,]  0.1725606  3.4535112 -1.38043518  3.6439042  5.4005650
 [10,] -2.3376856  4.8803363 -0.05927408  7.9275016  4.7013126
 [11,]  2.3032655  2.4974161  4.63961513  1.4021305 10.2302589
 [12,]  0.4470648  1.1660421 -0.70127807  6.3293479  6.6178080
 [13,]  2.5835127 -0.8768809  2.87405383  6.1361518  3.4851934
 [14,] -3.2769134  2.1721391  2.17317611  1.4170633  0.6446692
 [15,]  1.0771079 -2.5369687  4.89710339  1.8667695  4.4847933
 [16,]  7.2532218  3.0210221  0.56993065  2.4564492  6.9473683
 [17,]  4.0682441 -0.8198112  4.85259334  7.3296033  8.9541915
 [18,]  5.3991328 -0.9818425  1.73782230  2.9220433  4.9865858
 [19,]  2.0556183 -0.7470914  5.44869675  1.6452235  4.5236089
 [20,] -0.6277883  6.7255821  5.12606765  5.5721351  4.7081256
 [21,]  9.0139352  3.1350767  6.59366754  2.0351358  5.1865195
 [22,]  7.0598020  0.2869291  7.14368927  9.7213576  0.4251934
 [23,]  1.6430309  6.3806803  5.95776881  7.5234383  4.8860264
 [24,]  1.9473764  1.5386180  3.89690297  2.5333431  7.7217174
 [25,]  0.7960661 -1.5137800  2.84861591 -5.9986647  2.9309536

   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://http://oscarperpinan.github.io
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Select and plot specific row in rasterstack

2013-11-11 Thread Oscar Perpiñán Lamigueiro
If you know the row and column numbers use 's[row, column]':

s[2, 3]

or if you want to know the cell number:

myCell - cellFromRowCol(s, 2, 3)
s[myCell]

Oscar

Eddie Smith writes:

 Thanks a lot Oscar.

 I just realized that I had misunderstood how R listed the pixels.Row 1 is
 actually consist of pixel 1 to 5. Row 2, pixel 6 to 10 and so on.

 What I want to plot is actually a single pixel over time. For example, I
 want to plot pixel at row 2, column 3 for those 5 years.

 I know I can use plot(c(s[8])) but it's hard for me to know the pixel if
 for example I had much larger rasterstack and want to plot pixel at row 200
 and column 130.










 On Mon, Nov 11, 2013 at 10:13 AM, Oscar Perpi..n Lamigueiro 
 oscar.perpi...@upm.es wrote:

 Hello,

 You can extract a row from a RasterStack with s[i,]. Try this code:

 library(raster)
 library(zoo)
 library(lattice)

 r - raster(nrow=20, ncol=5)
 s - stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
 ## assign a time index to the 'RasterStack'
 s - setZ(s, seq(Sys.Date()-4, by='day', length=5))

 ## extract a row (10) and convert the result (a 'matrix') into a 'zoo'
 ## object using the time index of the 'RasterStack' object
 zz - zoo(t(s[10,]), order.by=getZ(s))

 xyplot(zz, superpose=TRUE)


 Best,

 Oscar.
 Eddie Smith writes:

  Dear list,
 
  How do I plot a specific row over time? For example I want to plot row
  10(layer.1 to 5 is actually year 1 to year 5.
 
  library(raster)
  r - raster(nrow=5, ncol=5)
  s - stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3)
 )) )
  s[]
 
   layer.1layer.2 layer.3layer.4layer.5
   [1,]  6.7134890  6.9141251  4.38213123  4.8995302  2.3105321
   [2,]  3.4323121  6.1074031 10.12872426  3.6728949  3.2252562
   [3,]  4.4370107  3.1397068  5.47572912  1.9692684  4.0064603
   [4,] -1.5588723  0.4075960 -0.7754  6.3589944  5.0355051
   [5,]  2.8095750  5.4264553  1.17820009  2.0665198  8.0491221
   [6,]  4.3422219  2.1106691  1.08638206  5.0640175  6.8057674
   [7,] -3.1072366 -1.1174633  6.28901706  5.0713964  1.8651354
   [8,] -0.5628539  2.1868130  1.21288191  0.3114011  3.0452161
   [9,]  0.1725606  3.4535112 -1.38043518  3.6439042  5.4005650
  [10,] -2.3376856  4.8803363 -0.05927408  7.9275016  4.7013126
  [11,]  2.3032655  2.4974161  4.63961513  1.4021305 10.2302589
  [12,]  0.4470648  1.1660421 -0.70127807  6.3293479  6.6178080
  [13,]  2.5835127 -0.8768809  2.87405383  6.1361518  3.4851934
  [14,] -3.2769134  2.1721391  2.17317611  1.4170633  0.6446692
  [15,]  1.0771079 -2.5369687  4.89710339  1.8667695  4.4847933
  [16,]  7.2532218  3.0210221  0.56993065  2.4564492  6.9473683
  [17,]  4.0682441 -0.8198112  4.85259334  7.3296033  8.9541915
  [18,]  5.3991328 -0.9818425  1.73782230  2.9220433  4.9865858
  [19,]  2.0556183 -0.7470914  5.44869675  1.6452235  4.5236089
  [20,] -0.6277883  6.7255821  5.12606765  5.5721351  4.7081256
  [21,]  9.0139352  3.1350767  6.59366754  2.0351358  5.1865195
  [22,]  7.0598020  0.2869291  7.14368927  9.7213576  0.4251934
  [23,]  1.6430309  6.3806803  5.95776881  7.5234383  4.8860264
  [24,]  1.9473764  1.5386180  3.89690297  2.5333431  7.7217174
  [25,]  0.7960661 -1.5137800  2.84861591 -5.9986647  2.9309536
 
[[alternative HTML version deleted]]
 
  ___
  R-sig-Geo mailing list
  R-sig-Geo@r-project.org
  https://stat.ethz.ch/mailman/listinfo/r-sig-geo


 --
 Oscar Perpi..n Lamigueiro
 Dpto. Ingenier.a El.ctrica (ETSIDI-UPM)
 Grupo de Sistemas Fotovoltaicos (IES-UPM)
 URL: http://http://oscarperpinan.github.io
 Twitter: @oscarperpinan


   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://http://oscarperpinan.github.io
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] How can I make a raster with latitude information?

2013-10-23 Thread Oscar Perpiñán Lamigueiro
Hello,

If your raster is 'r':

lat - init(r, v='y')

Oscar.

Manuel Spínola writes:

 Dear list members,

 I would like to make a raster with the latitude (in UTM) data to include
 this as a covariable in raster stack object to use for a species
 distribution model.  How can I do that?

 Best,

 Manuel


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
URL: http://http://oscarperpinan.github.io
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Google maps/ Blue Marble in R

2013-09-06 Thread Oscar Perpiñán Lamigueiro
Hello,

I am not sure if it fits your problem, but perhaps this example I posted
some months ago is useful for you:
http://procomun.wordpress.com/2013/04/24/stamen-maps-with-spplot/.
It combines a Stamen map (retrieved with the ggmap or OpenStreetMap
packages) with an SpatialPointsDataFrame displayed with spplot.

Could you send a sample of your data to give you a better answer?

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://http://oscarperpinan.github.io
Twitter: @oscarperpinan

zuzana zajkova writes:

 Hi,

 I would like to ask some questions... My aim is produce nice maps of
 distribution (kernels) of my studied species. So far I have been using
 rworldmap to get general view, but for presentation I would like to make
 the maps more beautiful :)
 I was able to get the Google maps (using dismo package) and create a map,
 but I am not able to add axes and legend to this map, what makes it quite
 useless as a map... Any suggestions?

 library(dismo)
 e - extent( -60 , -10 , 0 , 40 )  ## extent (long, long, lat, lat)
 r - gmap(e, type=satellite, scale=2)
 plot(r, interpolate=TRUE)


 Other thing is that I am open to use any other map as a background
 (preferably with topografhy and bathymetry), for example does anyone know
 if it is possible to use Blue Marble map for this?

 Thank you in advance for your suggestions.

 Zuzana

   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] how to use levelplot() with a geographic projection

2013-09-06 Thread Oscar Perpiñán Lamigueiro
Hi,

I think your problem is related with the way you define the
RasterLayer. You should use cellFromXY instead.  

Try the example below.

Best,

Oscar. 

## vectors of latitude and longitude with non-NA values
longitude - sample(seq(-130, -65, .1), 2000, replace=TRUE)
latitude - sample(seq(25, 50, .1), 2000, replace=TRUE)
xmn - min(longitude);
xmx - max(longitude)
ymn - min(latitude);
ymx - max(latitude)

## Build a raster fill with NA
myrast - raster(xmn=xmn, xmx=xmx, ymn=ymn, ymx=ymx, ncols=162, nrows=162)
## Extract the cell numbers corresponding to non-NA values
mycells - cellFromXY(myrast, cbind(longitude, latitude))
## and fill them with the appropiate values
myrast[mycells] - runif(length(longitude))

## Ready to plot...
ext - as.vector(extent(myrast))
boundaries - map('state', fill=TRUE, xlim=ext[1:2], ylim=ext[3:4], plot=FALSE)
IDs - sapply(strsplit(boundaries$names, :), function(x) x[1])
bPols - map2SpatialPolygons(boundaries, IDs=IDs, 
proj4string=CRS(projection(myrast)))

levelplot(myrast,
  panel = function(...) {
  panel.levelplot(...)
  sp.polygons(bPols)
  },
  margin=F)
Waichler, Scott R writes:

 Hi again,

 In working on this some more I discovered that I need to transpose a data 
 matrix, then flip the raster object created from the matrix to get the proper 
 rendering in a plot.  Can someone explain why that is?

 My example has to do with the state of California, with 2918 1/8-degree 
 cells.  I regret I can't provide a small working example--I don't know to 
 make one up that would clearly show correct vs. incorrect geographic 
 rendering.

 library(maps)
 library(maptools)
 library(raster)
 library(rasterVis)
 data(stateMapEnv)
 state.map - map(state, plot=F)

 # longitude and latitude are vectors giving the respective coordinates 
 # for cells that are non-NA (n=2918)

 xmn - min(longitude); xmx - max(longitude)
 ymn - min(latitude);  ymx - max(latitude)
 x.bounds - seq(xmn - 1/16, xmx + 1/16, by = 1/8)  # grid spacing is 1/8 
 degree
 y.bounds - seq(ymn - 1/16, ymx + 1/16, by = 1/8)
 ii - findInterval(longitude, x.bounds)  # indices
 jj - findInterval(latitude, y.bounds)   # indices
 index.matrix - cbind(ii,jj)
 num.long - length(x.bounds) - 1
 num.lat - length(y.bounds) - 1
 mat - array(NA, dim=c(num.long, num.lat)) # full, enclosing array with 
 rows=long and columns=lat
 mat[index.matrix] - runif(n=length(longitude))  # insert non-NA values in 
 the right cells

 # Why do I need to transpose the matrix then flip the raster for proper 
 rendering in levelplot?
 myrast - flip(raster(t(mat), xmn=xmn, xmx=xmx, ymn=ymn, ymx=ymx, 
   crs=+proj=longlat +datum=WGS84), 
direction=y)

 ext - as.vector(extent(myrast))
 boundaries - map('state', fill=TRUE, xlim=ext[1:2], ylim=ext[3:4], 
 plot=FALSE)
 IDs - sapply(strsplit(boundaries$names, :), function(x) x[1])
 bPols - map2SpatialPolygons(boundaries, IDs=IDs, 
 proj4string=CRS(projection(myrast)))

 levelplot(myrast,
   panel = function(...) {
   panel.levelplot(...)
   sp.polygons(bPols)
   },
   margin=F)

 --Scott Waichler


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://http://oscarperpinan.github.io
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Remove grey area when using gplot (rasterVis)

2013-07-22 Thread Oscar Perpiñán Lamigueiro
Hello,

Use na.value='transparent' inside scale_fill_gradient:

theme_set(theme_bw())
gplot(s) + geom_tile(aes(fill = value)) + 
  facet_wrap(~ variable) + 
  scale_fill_gradient(low = white, high = blue, na.value='transparent') +
  coord_equal()

Best,

Oscar

Manuel Spínola mspinol...@gmail.com writes:

 Dear list members,

 How can I remove the grey area that appear when using gplot from rasterVis

 Here is the reproducible example that come from the example of gplot:

 r - raster(system.file(external/test.grd, package=raster))
 s - stack(r, r*2)
 names(s) - c(meuse, meuse x 2)

 theme_set(theme_bw())
 gplot(s) + geom_tile(aes(fill = value)) +
   facet_wrap(~ variable) +
   scale_fill_gradient(low = white, high = blue) +
   coord_equal()


 Best,

 Manuel


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
LinkedIn: http://www.linkedin.com/in/oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] help for lattice plot

2013-07-10 Thread Oscar Perpiñán Lamigueiro
?print.trellis

Next time use the R-help mailing list
(https://stat.ethz.ch/mailman/listinfo/r-help) for these questions.

Best,

Oscar.


Saman Monfared samanmonfar...@gmail.com writes:

 Dear All,

 How can I plot some different plots in one page in lattice
 like par(mfrow=c(2,2)) in graphics package?


 p1-bwplot(m~PRED,data=PRED)
 p2-bwplot(R~Residual,data=PRED)
 xyplot(obs~PRED.v|method,data=PRED.v)
 histogram(~PRED.v|method,data=PRED.v)

 Thanks,

 Saman.

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] rasterVis: Region colours do not match the legend colours

2013-07-05 Thread Oscar Perpiñán Lamigueiro
Hello,

 However, I would still like to know how to manually set the region colours
 and extend the range of the legend, if it is possible. 

You have to use the at argument as you already did. However, you should
choose better breaks to display your data correctly. Here you will find
an example: http://rastervis.r-forge.r-project.org/FAQ.html#sec-1.

 I am also dealing with a time component, so while stacking the layers
 forces all the layer plots to use the same colours at the same values
 at, say time t=0, the range of data may change after some time has
 progressed, say at time t=10.

 Ultimately, the goal would be to make a gif to compare several climate model
 forecasts over time, like so:

 http://r-sig-geo.2731867.n2.nabble.com/file/n7584034/testing.gif 

 If the gif is viewable, notice how the legend is changing as the gif
 animation plays out - I want to, if possible, have the legend fixed and the
 regions coloured correctly according to the legend.

Use layout=c(1, 1). With your data:

levelplot(s, layout=c(1, 1))

If you need to create a movie use this code:

trellis.device(png, file='Rplot%02d.png')
levelplot(s, layout=c(1, 1))
dev.off()

## ffmpeg must be installed in your system
movieCMD - 'ffmpeg -i Rplot%02d.png output.mp4'
system(movieCMD)

Take a look at this thread for more info:
https://stat.ethz.ch/pipermail/r-sig-geo/2013-July/018735.html.

Best,

Oscar.


 I have read the link about creating an independent legend for each raster
 layer, but I think I would prefer to have just one legend.

 Thanks again,

 Jonathan



 --
 View this message in context: 
 http://r-sig-geo.2731867.n2.nabble.com/rasterVis-Region-colours-do-not-match-the-legend-colours-tp7584032p7584034.html
 Sent from the R-sig-geo mailing list archive at Nabble.com.

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
LinkedIn: http://www.linkedin.com/in/oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] gplot error in rasterVis

2013-05-30 Thread Oscar Perpiñán Lamigueiro
Hi,

With the current definition of gplot you have to add the layers you need
to plot (that's why you get the error No layers to plot). Take a look
at the example of the help page. With your example:

gplot(r) + geom_tile(aes(fill=value)) + coord_equal()

On the other hand, the warning when you use gplot is because both
latticeExtra and ggplot2 define the function layer. If ggplot2 is loaded
after rasterVis, the layer definition from latticeExtra becomes
masked. If you plan to use latticeExtra (for example, to add layers over
the result of a levelplot call) you should load ggplot2 before
rasterVis.

Best,

Oscar.

Natalie Wagenbrenner nwagenbren...@gmail.com writes:

 I'm trying to use gplot() in rasterVis to plot a RasterLayer object
 using ggplot2
 graphics, but I keep getting an error.  Here is a reproducible
 example:

 library(raster)
 library(rasterVis)

 r - raster(ncol=10, nrow=10)
 values(r) - 1:ncell(r)
 gplot(r)

 The following `from` values were not present in `x`: col, color, pch,
 cex, lty, lwd, srt, adj, bg, fg, min, max
 Error: No layers in plot

 I see the following warning when I load rasterVis:

 Loading required package: ggplot2

 Attaching package: ‘ggplot2’

 The following object(s) are masked from ‘package:latticeExtra’:

 layer

 Perhaps this is part of the problem? Or I am misunderstanding the
 gplot() methods somehow? Thanks for any suggestions.

 Natalie

 Session info:

 R version 2.14.1 (2011-12-22)
 Platform: x86_64-pc-linux-gnu (64-bit)

 locale:
  [1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C
 LC_TIME=en_CA.UTF-8
  [4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8
 LC_MESSAGES=en_CA.UTF-8
  [7] LC_PAPER=C LC_NAME=C
 LC_ADDRESS=C
 [10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8
 LC_IDENTIFICATION=C

 attached base packages:
 [1] grid  stats graphics  grDevices utils datasets
 methods   base

 other attached packages:
  [1] ggmap_2.3   RgoogleMaps_1.2.0.3 png_0.1-4
 maps_2.3-2  rasterVis_0.20-07
  [6] hexbin_1.26.2   latticeExtra_0.6-24 RColorBrewer_1.0-5
 lattice_0.20-0  ggplot2_0.9.3.1
 [11] rgdal_0.8-9 raster_2.1-25   sp_1.0-9
 ncdf_1.6.6  vimcom_0.9-8
 [16] setwidth_1.0-3  colorout_1.0-0

 loaded via a namespace (and not attached):
  [1] colorspace_1.2-2 dichromat_2.0-0  digest_0.6.3 gtable_0.1.2
   labeling_0.1 mapproj_1.2-1
  [7] MASS_7.3-16  munsell_0.4  plyr_1.8 proto_0.3-10
   reshape2_1.2.2   rjson_0.2.12
 [13] scales_0.2.3 stringr_0.6.2zoo_1.7-9

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Drawing lines in raster cells

2013-05-12 Thread Oscar Perpiñán Lamigueiro
Hi Lionel,

With this code you will draw lines connecting raster cells with a
certain value. I am not sure if you also need to build a SpatialLines
object with them (which you won't get with my code):

library(raster)
library(latticeExtra) ## to use +.trellis and layer()

r1-raster(ncols=10,nrows=10)
r1[]-sample(0:1,100,replace=TRUE)

## extract coordinates of those cells with a condition
myCells - Which(r1==1, cells=TRUE)
xy - xyFromCell(r1, myCells)

## border and border.lwd are only needed to highlight the cells boundaries
spplot(r1, at=c(0, 0.5, 1), border='black', border.lwd=0.3) +
layer(llines(xy, type='b', col='black'))


Best,

Oscar.

Lionel s6lih...@uni-bonn.de writes:

 Dear List,

 I would like to draw lines in raster cells with a certain values, I can 
 work around this with a for loop but as always this solution only works 
 for small datasets (which is not my case), I would therefore like to 
 have your opinion on this;

 #the code
 library(maptools) #to use spRbind
 out-NULL
 r1-raster(ncols=10,nrows=10)
 r1[]-sample(0:1,100,replace=TRUE)
 for(i in 1:ncell(r1)){
if(r1[i]==1){
 lines-SpatialLines(list(Lines(list(Line(matrix(c(xyFromCell(r1,i)+(res(r1)/2),xyFromCell(r1,i)-(res(r1)/2)),ncol=2,byrow=TRUE))),ID=as.character(i
  if(is.null(out)){
out-lines }
 else {out-spRbind(out,lines)}
  }
print(i)
 }

 Thank you in advance,


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] colors (and other issues) in rasterVis()

2013-05-03 Thread Oscar Perpiñán Lamigueiro
Hello,

1.- Use names.attr to define the labels of each panel if they are
different from the layers names.

2.- The axes can be customized with scales. To suppress them completely
use scales=list(draw=FALSE).

3.- The colors are defined with col.regions (you were using col.region)
or par.settings. There are some examples with par.settings and
predefined themes here: http://rastervis.r-forge.r-project.org/#themes.
I will improve the documentation to clarify this point.

This code should work for your three requirements:

r - raster(nrow=10, ncol=10)
r[] - runif(100)
s - stack(lapply(1:8, function(i)r))

levelplot(s, scales=list(draw=FALSE), colorkey=FALSE,
  col.regions=gray.colors(128,gamma=0.5),
  names.attr=paste0('MNF-', 1:8))

myTheme - rasterTheme(region=gray.colors(128,gamma=0.5))
levelplot(s, scales=list(draw=FALSE), colorkey=FALSE,
  par.settings=myTheme,
  names.attr=paste0('MNF-', 1:8))

levelplot(s, scales=list(draw=FALSE), colorkey=FALSE,
  par.settings=GrTheme(),
  names.attr=paste0('MNF-', 1:8))

Best,

Oscar.
Agustin Lobo alobolis...@gmail.com writes:

 Hi!
 I do not get to plot a set of 8 raster layers from a brick the way I
 want with rasterVis()
 I do:
 require(rasterVis)
 levelplot(adlsEMNFVIS[[1:8]],axes=FALSE,colorkey=FALSE,col.region=gray.colors(128,gamma=0.5))

 I want to:
 1. Do not plot the names of the layers or plot a different text. i.e.
 paste(MNF-,1:8,sep=)
 2. Do not plot the axes or at least the axes text (the numbers).
 3. Use a grey scale.

 I've gone through the man page and I think that I should use
 par.settings=, but the help page
 links to another page and that one to another... and finally get lost.

 Any help appreciated!

 Thanks

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] zApply

2013-04-24 Thread Oscar Perpiñán Lamigueiro
Hello Kate,

I have modified your code. Try the code I copy below.

Best,

Oscar.

library(zoo)
## You were using library(base) but I am sure you really want raster :-)
library(raster)

## Data example: substitute it with your brick and time index
r - raster(ncol=2, nrow=2)
index - seq(as.Date('2000-01-01'), as.Date('2012-12-31'), by='day')
RR - brick(lapply(seq_along(index), function(x) setValues(r, rnorm(ncell(r)

RR - setZ(RR,index)
## If you only need monthly averages, first you have to define an
## auxiliary function to extract the month from the time index
month - function(x)as.numeric(format(x, '%m'))
RRmonth - zApply(RR, by=month, FUN=mean)
## But if you need monthly averages per year, zoo::as.yearmon is
## your function
RRyearmon - zApply(RR,by=as.yearmon, FUN=mean)

KaTe tersagokatr...@gmail.com writes:

 Dear R-sig-geo, 
 I have a problem with the use of zApply on a large Rasterbrick made from a
 netcdf file. 
 It concerns a file with daily rainfall data for a period of 15 years on a
 european scale (see details below)

 -
 class   : RasterBrick 
 dimensions  : 201, 464, 93264, 6575  (nrow, ncol, ncell, nlayers)
 resolution  : 0.25, 0.25  (x, y)
 extent  : -40.5, 75.5, 25.25, 75.5  (xmin, xmax, ymin, ymax)
 coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
 names   : X1995.01.01, X1995.01.02, X1995.01.03, X1995.01.04,
 X1995.01.05, X1995.01.06, X1995.01.07, X1995.01.08, X1995.01.09,
 X1995.01.10, X1995.01.11, X1995.01.12, X1995.01.13, X1995.01.14,
 X1995.01.15, ... 
 Date: 1995-01-01, 2012-12-31 (min, max)
 varname : rr 
 --

 Now, I want to change this brick with daily data into a brick of monthly
 means (per year) prior to data extraction. I am quite convinced I should use
 zApply for this, but up till now I was not able to use (read: fully
 understand) the few examples from the raster manual or this list
 successfully. 
 I tried the code below, with RR being the raster brick: 

 library(zoo)
 library(base)
 index- seq(as.Date('1995-01-01'), as.Date('2012-12-31'), by='day')
 RR-setZ(RR,index)
 system.time(RRmonths-zApply(RR,by=month, FUN=mean))

 when I try this on a subset of 2 years I only get a single raster file, so
 clearly something is wrong. 
 Even if this works, I fear this code will give me the monthly averages over
 the whole series, while I need mean monthly values per year (using yearmon
 gives errors). 

 I am new to this field, hope anyone could give me some hints to move
 forward. (Or some other approach )
 Thanks in advance,
  
 Kate
 PhD, University of Antwerp







 --
 View this message in context: 
 http://r-sig-geo.2731867.n2.nabble.com/zApply-tp7583405.html
 Sent from the R-sig-geo mailing list archive at Nabble.com.

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] R language GIS moving points

2013-04-14 Thread Oscar Perpiñán Lamigueiro
Hello,

You could try grid.animate from the gridSVG package. Here you will find
an example:

http://www.stat.auckland.ac.nz/~paul/Velvet/gapminderOnePanel.svg.html
(code at
http://www.stat.auckland.ac.nz/~paul/Talks/Genentech2011/gapminderLattice.R)

Best,

Oscar.


endri81 endr...@gmail.com writes:

 Hello group,
 Trying to load a map from Google Maps.
 Main idea is to show a bus route in R language and to simulate some moving
 points on this route representing buses moving from one point to the other.
 Any idea which package to use for this and maybe some advices would be very
 thankful.
 Best Regards



 --
 View this message in context: 
 http://r-sig-geo.2731867.n2.nabble.com/R-language-GIS-moving-points-tp7583305.html
 Sent from the R-sig-geo mailing list archive at Nabble.com.

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Increasing font size in a levelplot graphic

2013-03-26 Thread Oscar Perpiñán Lamigueiro
Hi,

On the other hand, perhaps your problem arises when you export the
graphic using large values for width and height without modifying the
resolution.

Try this:

library(raster)
library(rasterVis)

r - raster()
r - init(r, runif)

## res=72 if none is provided
png('smallFontSize.png', width=4000, height=4000)
levelplot(r)
dev.off()

png('correctFontSize.png', width=4000, height=4000, res=600)
levelplot(r)
dev.off()


Best,

Oscar.
Pascal Oettli kri...@ymail.com writes:

 Hi,

 For example:

 p.strip - list(cex=1.5, lines=2, fontface='bold')
 ckey - list(labels=list(cex=1.5, col='magenta'), height=0.5)
 x.scale - list(cex=1, alternating=1, col='red')
 y.scale - list(cex=1, alternating=1, col='blue')

 levelplot(s, colorkey=ckey, par.strip.text=p.strip, 
 scales=list(x=x.scale, y=y.scale))

 HTH,
 Pascal


 On 26/03/13 12:16, Thiago V. dos Santos wrote:
 Dear R-SIGgers,

 This question is related to the rasterVis package. Please reproduce the 
 following plot:

 library(raster)
 library(rasterVis)

 r1=r2=r3=raster(nr=100, nc=100)
 r1[]-r2[]-r3[]-1:ncell(r1)
 s-stack(r1,r2,r3)
 levelplot(s)

 On my Mac, I think the text size is too small. Increasing picture dimensions 
 won't work - graph size will increase but text still looks small.

 So my question arises: how can I increase axis, scale and title font size in 
 a levelplot graphic? I've skimmed over both rasterVis and lattice 
 documentation and haven't found any clues.


 Any help appreciated.

 Best regards,
 Thiago.

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Problem with projection in NetCDF file

2013-03-19 Thread Oscar Perpiñán Lamigueiro
Hello,

If anyone is interested in the datasets related to my last question, I finally
managed to work with them using these proj4 strings:

2D: http://mandeo.meteogalicia.es/thredds/catalogos/WRF_2D/catalog.html
+proj=lcc +lon_0=-14.1 +lat_0=34.823 +lat_1=43 +lat_2=43 +x_0=536402.3 
+y_0=-18558.61 +units=km +ellps=WGS84

3D: http://mandeo.meteogalicia.es/thredds/catalogos/WRF/catalog_grib.html
+proj=lcc +lon_0=-14.1 +lat_0=43 +lat_1=43 +lat_2=43 +units=km +ellps=WGS84 
+a=6371400 +b=6371400

Best,

Oscar.

Oscar Perpiñán Lamigueiro oscar.perpi...@gmail.com writes:

 I am trying to use the NetCDF files available at the
 Meteogalicia-THREDDS server
 (http://www.meteogalicia.es/web/modelos/threddsIndex.action). I am
 having problems with the projection parameters (see figure attached for
 a quick understanding of the problem).

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Antw: arithmetic with layers from a raster stack/brick

2013-03-01 Thread Oscar Perpiñán Lamigueiro
Hi,

Another solution:

r - raster(nrows=2, ncols=2)
r[] - 1:ncell(r)
s - stack(r, r, r, r)
names(s) - letters[1:4]

## all the layers
sum(s)
## only a subset
sum(subset(s, c('a', 'b')))

Best,

Oscar.

Etienne B. Racine etienn...@gmail.com writes:

 I wouldn't recommend using this for general purpose, but this should work:

 for (i in 1:nlayers(s)) {
   assign(names(s)[i], s[[i]])
 }

 Etienne


 2013/2/28 Matteo Mattiuzzi matteo.mattiu...@boku.ac.at

 Dear Ani,


 Your a and b are not objects, they are the name the layers in your
 object s. So you can't treat it that way.


 Maybe this is what you want?


 require(raster)
 r- raster(nrows=2, ncols=2)
 r[]-1:ncell(r)
 s-stack(r,r)
 names(s)-c(a,b)



 r1- s[[a]] + s[[b]]


 Matteo

  aniruddha ghosh  28.02.13 21.26 Uhr 
 Dear List,

 I'm trying to perform some arithmetic operation with layers of a raster
 object. What I'm trying is

 require(raster)
 r- raster(nrows=2, ncols=2)
 r[]-1:ncell(r)
 s-stack(r,r)
 names(s)-c(a,b)

 # now I want to add the layers of the raster r using their corresponding
 names,i.e. a and b so that I get

 r1-a+b

 I don't want to use subset (or any other methods) to define a or b.
 This may be very trivial, but I couldn't do it.

 Any suggestions?

 Thanks
 --
 Ani

 [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo


   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Legend problem with levelplot and categorical rasters

2013-02-27 Thread Oscar Perpiñán Lamigueiro
Hello,

This is a bug in rasterVis::levelplot. The ticks locations of the legend are 
incorrectly
calculated. I will try to fix it as soon as possible.

Best,

Oscar.
Alastair Potts pott...@gmail.com writes:

 Good day all,

 I can't seem to wrap my head around why this is not working. Below are two
 examples of plotting a categorical raster. The first has a continuous
 series of integers (i.e. 1,2,3) whereas the second has breaks (i.e. 1,3,5).
 The legend in the second levelplot example is incorrect as it seems to be
 expecting a continuous series. I have very good reasons to have a broken
 series and would very much like to have to avoid recoding the to a
 continuous series.

 Any suggestions would be greatly appreciated. Thanks in advance.

 Examples below.

 ## Example 1
 library(raster)
 library(rasterVis)
 ## Categorical data
 r - raster(nrow=10, ncol=10)
 r[] = 1
 r[51:100] = 2
 r[3:6, 1:5] = 3
 r - ratify(r)

 rat - levels(r)[[1]]
 rat$landcover - c('Pine', 'Oak', 'Meadow')
 levels(r) - rat
 r
 levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))

 ## Example 2
 ## Categorical data
 r - raster(nrow=10, ncol=10)
 r[] = 1
 r[51:100] = 3
 r[3:6, 1:5] = 5
 r - ratify(r)

 rat - levels(r)[[1]]
 rat$landcover - c('Pine', 'Oak', 'Meadow')
 levels(r) - rat
 r
 levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))


-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Problem with projection in NetCDF file

2013-02-22 Thread Oscar Perpiñán Lamigueiro
Hello,

Sorry in advance for this long email.  

I am trying to use the NetCDF files available at the
Meteogalicia-THREDDS server
(http://www.meteogalicia.es/web/modelos/threddsIndex.action). I am
having problems with the projection parameters (see figure attached for
a quick understanding of the problem).

For example, I download and open the file
wrf_arw_det_history_d01_20130214_.nc4 (~85Mb):

library(raster) ## 2.1.6
library(rgdal) ## 0.8.1


download.file('http://mandeo.meteogalicia.es/thredds/fileServer/wrf_2d_36km/fmrc/files/20130214/wrf_arw_det_history_d01_20130214_.nc4',
  destfile='~/temp/wrf_arw_det_history_d01_20130214_.nc4')

## Temperature values
temps - brick('~/temp/wrf_arw_det_history_d01_20130214_.nc4', 
varname='temp')
## This file uses the LCC projection
projection(temps)
## +proj=lcc +lon_0=-14.103814697 +lat_0=24.2280006408691
## +x_0=2182.62935 +y_0=-269.65597 +lat_1=43 +lat_2=43 +ellps=WGS84

## Latitude
lats - raster('~/temp/wrf_arw_det_history_d01_20130214_.nc4',
   varname='lat')
## However the latitude layer does not inherit that projection...
projection(lats)
## +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## Therefore, a correction is needed
projection(lats) - projection(temps)

## Longitude
lons - raster('~/temp/wrf_arw_det_history_d01_20130214_.nc4', 
varname='lon')
projection(lons) - projection(temps)

I detect the problem with the projection parameters when overlaying the
administrative boundaries:

download.file('http://gadm.org/data/rda/ESP_adm0.RData',
  destfile='~/temp/ESP_adm0.RData')
load('~/temp/ESP_adm0.RData') ## a new object named gadm
projection(gadm)
## +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0

projLCC - projection(temps)
spainLCC - spTransform(gadm, CRS(projLCC))

library(rasterVis)
levelplot(temps, layers=10) +
  layer(sp.polygons(spainLCC, lwd=.4))+
  contourplot(lons) + contourplot(lats)

Then, after inspecting the metadata I found that x and y are using km
units. Since this information has not been transferred to the proj4
string, I modify the projection:

projLCC - paste(projection(temps), '+units=km')
projection(temps) - projLCC
projection(lons) - projLCC
projection(lats) - projLCC
spainLCC - spTransform(gadm, CRS(projLCC))

However, the result is still not correct (see temps.jpg):

levelplot(temps, layers=10) +
  layer(sp.polygons(spainLCC, lwd=.4))+
  contourplot(lons) + contourplot(lats)

Could it be that the parameters of the proj4 string are incorrect? Maybe
am I missing something?  I have tested this same file with the Godiva2
viewer and it is correctly displayed:
http://mandeo.meteogalicia.es/thredds/godiva2/godiva2.html?menu=layer=tempelevation=0time=2013-02-22T14:29:45Zscale=267.15,313.15bbox=-49.182593,13.500592,18.788996,66.603396server=http://mandeo.meteogalicia.es/thredds/wms/wrf_2d_36km/fmrc/files/20130214/wrf_arw_det_history_d01_20130214_.nc4.

Thanks in advance.

Best,

Oscar.

attachment: temps.jpg-- 
Oscar Perpiñán Lamigueiro
Grupo de Sistemas Fotovoltaicos (IES-UPM)
Dpto. Ingeniería Eléctrica (EUITI-UPM)
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Alternative to zonal for large images

2013-02-12 Thread Oscar Perpiñán Lamigueiro
Hello,

I think that the combination of the raster and data.table packages can
be really useful. For example, here it is a very simplified version of
zonal using the data.table methods. It provides the same results about
10 times faster.

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan


library(data.table)

myZonal - function (x, z, stat = mean, digits = 0, na.rm = TRUE, 
 ...) {
  fun - match.fun(stat)
  vals - getValues(x)
  zones - round(getValues(z), digits = digits)
  rDT - data.table(vals, z=zones)
  setkey(rDT, z)
  rDT[, lapply(.SD, fun), by=z]
}

## A RasterLayer with 1e6 cells
r - raster(ncols=1000, nrows=1000)
r[] - runif(ncell(r)) * 1:ncell(r)
z - r
z[] - rep(1:10, each=ncell(r)/10)

 system.time(print(zonal(r, z)))
  zonemean
 [1,]1  24936.45
 [2,]2  75138.38
 [3,]3 124880.63
 [4,]4 175018.38
 [5,]5 224632.18
 [6,]6 274356.22
 [7,]7 325141.16
 [8,]8 375625.27
 [9,]9 424195.16
[10,]   10 474595.73
   user  system elapsed 
  3.988   0.220   4.215 
 system.time(print(myZonal(r, z)))
 z  vals
 1:  1  24936.45
 2:  2  75138.38
 3:  3 124880.63
 4:  4 175018.38
 5:  5 224632.18
 6:  6 274356.22
 7:  7 325141.16
 8:  8 375625.27
 9:  9 424195.16
10: 10 474595.73
   user  system elapsed 
  0.464   0.024   0.489 

## Now with a RasterBrick
s - brick(r, nl=4)
s[] - runif(ncell(s)*4)

 system.time(print(zonal(s, z)))
  zone   layer.1   layer.2   layer.3   layer.4
 [1,]1 0.4986786 0.5007106 0.5001397 0.4994188
 [2,]2 0.4993135 0.5009089 0.5006163 0.5001419
 [3,]3 0.4989671 0.5013064 0.4983836 0.5004493
 [4,]4 0.5005992 0.5009225 0.4971442 0.4999080
 [5,]5 0.4998065 0.4989140 0.5000887 0.5014669
 [6,]6 0.5010002 0.5008529 0.4987527 0.5012223
 [7,]7 0.5002876 0.5006790 0.4982280 0.4999350
 [8,]8 0.5006809 0.4997827 0.5000287 0.4995565
 [9,]9 0.4993470 0.5010943 0.5005641 0.5003999
[10,]   10 0.4994278 0.4991750 0.4978472 0.5003966
   user  system elapsed 
 10.009   0.560  10.584 
 system.time(print(myZonal(s, z)))
 z   layer.1   layer.2   layer.3   layer.4
 1:  1 0.4986786 0.5007106 0.5001397 0.4994188
 2:  2 0.4993135 0.5009089 0.5006163 0.5001419
 3:  3 0.4989671 0.5013064 0.4983836 0.5004493
 4:  4 0.5005992 0.5009225 0.4971442 0.4999080
 5:  5 0.4998065 0.4989140 0.5000887 0.5014669
 6:  6 0.5010002 0.5008529 0.4987527 0.5012223
 7:  7 0.5002876 0.5006790 0.4982280 0.4999350
 8:  8 0.5006809 0.4997827 0.5000287 0.4995565
 9:  9 0.4993470 0.5010943 0.5005641 0.5003999
10: 10 0.4994278 0.4991750 0.4978472 0.5003966
   user  system elapsed 
  0.652   0.284   0.939

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] rasterVis::levelplot key='top' error

2012-10-11 Thread Oscar Perpiñán Lamigueiro
Hello Jonathan,

The problem is that key at top interferes with the margin
plot. Therefore, as you have already found, you have to set 
margin = FALSE.

Best,

Oscar.
 OK, sorry for the previous post.  I am able to achieve my desired result this
 way by over-riding some defaults:

 levelplot(RST, 
   region = FALSE,
   margin = FALSE,
   colorkey = FALSE,
   key = list(space = 'top',
  points = list(col = 'black',
type = 'p',
pch = 20),
  text = list('test')))

 Thank you,
 Jonathan





 --
 View this message in context: 
 http://r-sig-geo.2731867.n2.nabble.com/rasterVis-levelplot-key-top-error-tp7581134p7581136.html
 Sent from the R-sig-geo mailing list archive at Nabble.com.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] color schemes for landcover plots of multiple rasters

2012-09-25 Thread Oscar Perpiñán Lamigueiro
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Although it is not fully automatic, you may be interested in this
example (http://procomun.wordpress.com/2012/02/20/maps_with_r_2/):
 library(raster)
 library(rasterVis)
 library(colorspace)
 ## http://neo.sci.gsfc.nasa.gov/Search.html?group=3D20
 landClass - raster('241243rgb-167772161.0.TIFF')
 ## China and India
 ext - extent(65, 135, 5, 55)
 landClass - crop(landClass, ext)
 ## Codes: http://eoimages.gsfc.nasa.gov/images/news/NasaNews/ReleaseImages=
/LCC/Images/lcc_key.jpg
 landClass[landClass %in% c(0, 254)] - NA
 landClass - cut(landClass, c(0, 5, 11, 14, 16))
 classes - c('FOR', 'LAND', 'URB', 'SNOW')
 nClasses - length(classes)
 rng - c(minValue(landClass), maxValue(landClass))
 ## define the breaks of the color key
 my.at - seq(rng[1]-1, rng[2])
 ## the labels will be placed vertically centered
 my.labs.at - seq(rng[1], rng[2])-0.5
 levelplot(landClass, at=3Dmy.at, margin=3DFALSE,
  col.regions=3Dterrain_hcl(nClasses),
  colorkey=3Dlist(labels=3Dlist(labels=3Dclasses, ## classes names =
as labels
  at=3Dmy.labs.at)))
 I will try to modify rasterVis::levelplot to work automatically with
 categorical data.
 Best,
 Oscar.
steven mosher mosherste...@gmail.com writes:
  I'm plotting a series ( a few hundred )  of  rasters that are filled with
  landcover data,   integers
 
  Normally, these are  integers such as  c(11,12,21,22,23,31,32,41,42,43,5=
1,
   etc etc)
  where each value corresponds to a landcover type.
 
  I want all of these plots to have consistent colors and legends. However,
  not every plot has
  a complete set of land cover types.   What I tried was the following.
 
  I took all the landcover values in the raster and reclassified them so t=
hat
  I got a  seq from
  1..n.   and then I made a vector of colors the same length
 
  However, when a land type if missing I still get   errors.  I tried using
   breaks() and that
  helped a little but I would still get  errors
 
  Here is a toy example
 
  r - raster(nrow=3D10,ncol=3D10)
  #  slot in some values
  r[1:12]-0
  r[13:34]-1
  r[35:76]-2
  r[77:95]-3
  r[96:100]-4
 
  #  define colors
  myColors - c(black,green,orange,pink,blue)
 
  plot(r,col=3DmyColors)
 
  #  swicth the 4 to 0
  r - subs(r,data.frame(Id=3D c(0,1,2,3,4), v=3Dc(0,1,2,3,0)))
 
  plot(r,col=3DmyColors)
 
  Another way to ask this is how do I get the function to recognize that I
  watch categorical colors instead of
  continuous ones. or should I change the colors dynamically according to =
the
  actual values found in that
  particular map.
 
  I tried  breaks() no joy
 
 
  Steve
 
   [[alternative HTML version deleted]]
 --=20
 Oscar Perpi=C3=B1=C3=A1n Lamigueiro
 Dpto. Ingenier=C3=ADa El=C3=A9ctrica
 EUITI-UPM
Date: Tue, 25 Sep 2012 13:20:45 +0200
In-Reply-To: cafflnersk9rg8l4pgahqqkhbchnsocixokrofzht_tn8vkd...@mail.gmai=
l.com
(steven mosher's message of Sun, 23 Sep 2012 22:27:38 -0700)
Message-ID: 87ipb21h82@gmail.com
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Plot spatial time series

2012-06-11 Thread Oscar Perpiñán Lamigueiro
Thiago Veloso thi_vel...@yahoo.com.br writes:
Hello,

Another approach is to use the zoo package with setZ and cellStats. 

With a toy example:

library(raster)
library(zoo)

fn - system.file(external/test.grd, package=raster)
r - raster(fn)
ll - lapply(runif(12), function(x)r*x)
s - stack(ll)

idx - as.yearmon(2011 + seq(0, 11)/12)
s - setZ(s, idx)
avg - zoo(cellStats(s), idx)

## plot method for the zoo objects
plot(avg)

## or with lattice, xyplot method for the zoo objects
library(lattice)
xyplot(avg)

Best,

Oscar.
   Matthew,

   Thank you very much for the suggestion. You assumed correctly: I wanted to 
 plot an average of the whole raster.

   I managed to plot the data (please see 
 http://img137.imageshack.us/img137/601/screenshotan.png), but it's still 
 precarious. Right now I am tying to improve the plot with ggplot2 package!

   Cheers,
   Thiago.


 - Original Message -
 From: Matt Landis lan...@isciences.com
 To: Thiago Veloso thi_vel...@yahoo.com.br
 Cc: R-SIG list r-sig-geo@r-project.org
 Sent: Friday, June 8, 2012 3:45 PM
 Subject: Re: [R-sig-Geo] Plot spatial time series

 Fixing typos:
 tmp.df - data.frame(date = rep(NA, length(files)), lai = NA)
 for ( i in 1:length(files) ){
      f - files[i]
    cat('Reading file: ', f, '\n')
    tmp.df$date[i] - regmatches(f, regexpr('[0-9]{7}', f))
    tmp.df$lai[i] - mean(getValues(r), na.rm = TRUE)
 }

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Adding additional items to plot

2012-05-17 Thread Oscar Perpiñán Lamigueiro
Adam Sparks adamhspa...@gmail.com writes:

 Dear all,
 I'm attempting to produce some finished product maps using R and have been
 struggling with an issue.

 I want to use a hillshade object created from a DEM using the hillShade()
 function as a backdrop for my raster data that I'm presenting.

 Behind that I want to use lightsteelblue2 as the color where there is water.

 On top of this I want to plot the country outlines for the areas of
 interest.

 So in summary I have:
  the first layer, blue for water
  the second layer, hillshade DEM
  the third layer, my raster data I'm presenting
  the fourth layer, the country outline


Hello,

Try this approach using rasterVis and latticeExtra:

library(raster)
library(rasterVis)
library(maptools) ##for readShapeLines
library(latticeExtra)

## Get the data from gadm and data-vis
download.file('http://www.gadm.org/data/shp/ETH_adm.zip', '~/temp/ETH_adm.zip')
unzip('~/temp/ETH_adm.zip', exdir='~/temp')
download.file('http://www.diva-gis.org/data/msk_alt/ETH_msk_alt.zip', 
'~/temp/ETH_msk_alt.zip')
unzip('~/temp/ETH_msk_alt.zip', exdir='~/temp')
download.file('http://www.diva-gis.org/data/wat/ETH_wat.zip', 
'~/temp/ETH_wat.zip')
unzip('~/temp/ETH_wat.zip', exdir='~/temp')

## Read the files
proj - CRS(' +proj=longlat +ellps=WGS84')
ethAdm - readShapeLines('~/temp/ETH_adm1.shp', proj4string=proj)
ethWat - readShapeLines('~/temp/ETH_water_lines_dcw.shp', proj4string=proj)
ethAlt - raster('~/temp/ETH_msk_alt')

## and plot using the +.trellis and layer functions
## from latticeExtra
levelplot(ethAlt, par.settings=GrTheme) +
  layer(sp.lines(ethWat, col='blue', lwd=0.6)) +
  layer(sp.lines(ethAdm, col='black', lwd=0.7))

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] create a TS with multiple raster files

2012-04-18 Thread Oscar Perpiñán Lamigueiro
Jacob van Etten jacobvanet...@yahoo.com writes:

 Dear Nora,

 The best thing would be to read the vignette of the raster package first.

 A combination of raster layers is not a data frame, but a stack.

 This is how you make one, following your example:


 st - get(list.files(pattern='*.rst')[1])

 for (f in list.files(pattern='*.rst')[-1]) {st - stack(st, get(f))}

Another approach is to pass the result of list.files directly to stack
(if I am not wrong you do not want the first file to be included, that's
why I use [-1]):

library(raster)

rst - list.files(pattern='*.rst')
s - stack(rst[-1])

If this stack is a space-time data you can use the setZ function. If idx
is the time index of the data:

s - setZ(s, idx)

Best,

Oscar.


 
  From: Nora Schmid noerchen...@gmail.com
 To: r-sig-geo@r-project.org 
 Sent: Tuesday, 17 April 2012, 9:25
 Subject: [R-sig-Geo] create a TS with multiple raster files

 Hello,

 Im new in R and dont have lots of experiences with programming...
 Im trying to create a time series:
 I read my raster data with the following:

 for (f in list.files(pattern='*.rst')){assign(f, raster(f))}

 How can I create afterwards a time series with the files I loaded? How
 can I assign all files to one data frame? Whats the best way to create
 from multiple raster files on time series?

 Thanks a lot in advance,

 yours

 Nora

   [[alternative HTML version deleted]]


 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo
   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Saving plot as PDF from functions levelplot and gplot from rasterVis package

2012-03-21 Thread Oscar Perpiñán Lamigueiro
Manuel Spínola mspinol...@gmail.com writes:

 Dear list members,

 How can I save a map on pdf plotted with the functions levelplot or gplot
 from the rasterVis package without loosing quality of the map.

 class(maparaster)
 [1] RasterLayer
 attr(,package)
 [1] raster


 pdf(mp.pdf)
 levelplot(maparaster)
 dev.off()

Hello,

You should use trellis.device with lattice objects:

f - system.file(external/test.grd, package=raster)
r - raster(f)

##default
trellis.device(pdf, file='mp.pdf')
levelplot(r)
dev.off()


##smaller file
trellis.device(pdf, file='mpRaster.pdf')
levelplot(r, panel=panel.levelplot.raster)
dev.off()

##smaller file and interpolate
trellis.device(pdf, file='mpInterpolate.pdf')
levelplot(r, panel=panel.levelplot.raster, interpolate=TRUE)
dev.off()

Best,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Displaying temporal variation of raster data

2012-03-15 Thread Oscar Perpiñán Lamigueiro
Thiago Veloso thi_vel...@yahoo.com.br writes:

  Dear R colleagues,

  I have a netcdf file containing ten time slices, where each slice 
 corresponds to yearly deforestation rates over the Amazon forest. Values 
 range from 0 (no deforest) to 1 (maximum deforest). Please take a look in a 
 sample of the data: 
 http://imageshack.us/photo/my-images/23/deforestamazon.png/

  My objective is to show the temporal variation of this data. How can I 
 produce categorical histograms for each one of the ten years? What I have in 
 mind is something like the lower panel of this figure: 
 http://www.crwr.utexas.edu/gis/gishydro05/Time/DHI_Temporal_Analyst/TemporalAnalystForArcGIS.htm,
  but plotting bars relative to three or four classes of deforesting rates 
 instead of lines.

  Is it possible to produce such a figure using any SIG-related R package?
Hello,

The combination of 'setZ' from raster with 'histogram' (or 'densityplot') from
rasterVis is a suitable solution:

library(raster)
library(rasterVis)

r - raster(ncol=10, nrow=10)
s - stack(lapply(1:12, function(x)setValues(r, runif(ncell(r)
idx - seq(as.Date('2000-01-15'), length.out=12, by='month')
s - setZ(s, idx)
layerNames(s) - format(idx, '%b') 
s

histogram(s)
densityplot(s)

And if you use 'zoo':

library(zoo)
histogram(s, FUN=as.yearqtr)
densityplot(s, FUN=as.yearqtr)

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Displaying temporal variation of raster data

2012-03-15 Thread Oscar Perpiñán Lamigueiro
Barry Rowlingson b.rowling...@lancaster.ac.uk writes:

 On Thu, Mar 15, 2012 at 4:45 PM, Thiago Veloso thi_vel...@yahoo.com.br 
 wrote:
  Dear Jan (cc Oscar, who also gave a tip),
  Thanks for your input. Sorry for not stating my problem concisely. This 
 time I have shared a simplified sample of my data: http://db.tt/XXDtRee1.
  Notice that this netcdf file contains three time dimensions - corresponding 
 to years 2000 to 2002 (entire dataset contains ten). Also notice that values 
 range from 0 to 1. As we can see in the file, each year is marked by 
 different degrees of deforestation rates.
  Below is the code I am using to load the multi-band file:
 library (raster) deforest-brick(/home/thiago/Dropbox/defor-3-years.nc

  From there, I can go:

   meltR=melt(as.array(deforest))
   meltR$class=cut(meltR$value,c(0,0.3,0.6,1))
   p = ggplot(meltR,aes(x=class))
   p + geom_histogram(aes(fill=class))+facet_grid(~X3)

  And get a very pretty set of histograms. You need the ggplot package.

And for completeness, the lattice way ;-):

layerNames(deforest) - as.character(2000:2002)

dat - as.data.frame(deforest)
datLong - stack(dat) ##wide to long

datLong$class - cut(datLong$values, c(0, 0.3, 0.6, 1))
tt - table(datLong$ind, datLong$class)

library(lattice)
barchart(tt, auto.key=list(space='right'), horizontal=FALSE, stack=FALSE)

You can even use the 'cut' method for 'Raster*':

defClass - cut(deforest, c(0, 0.3, 0.6, 1))
dat - stack(as.data.frame(defClass))
tt - table(dat$ind, dat$values)
barchart(tt, auto.key=list(space='right'), horizontal=FALSE, stack=FALSE)

Best,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Aggregate time series grid data temporally

2012-03-12 Thread Oscar Perpiñán Lamigueiro
senani karunaratne senaw...@yahoo.com writes:
 Hi Ping, 

 You can read your grid files to R. 

 Recently I  read monthly grid data for time series and they can be stacked in 
 R. 

 Use package Raster for stacking purpose. Code I used is given below

 setwd (D:\\WORKINGS)
 # check your data in folder
 dir()
 library (raster)
 # list all files of interest:
 weather- list.files()
 # Read to R:
 require (raster)
 stacked - stack (lapply(weather,raster))

 Look for help file of the raster package where you can get aggregates etc
 This approach is very simple and it works for me. 

Besides, the 'setZ' and 'zApply' functions of the 'raster' package could be 
useful for you since
you are using raster time series.

Best,

Oscar.

 Date: Sat, 10 Mar 2012 07:52:21 -0700
 From: ping yang pingyang@gmail.com
 To: R-sig-Geo@r-project.org
 Subject: [R-sig-Geo] Aggregate time series grid data temporally
 Message-ID:
     cak8gsg_iuc_bz6jvoy_ymab_rn9qb4e_9jmk7kwr+vtn919...@mail.gmail.com
 Content-Type: text/plain

 Hi,

 I am a newbie of R, I have time series (6 hours) weather data(represented
 as muti-layer grids), what I plan to do is to aggregate these grids
 temporally(from 6 hours to daily), Can I do it with R? some instructions or
 suggestions?

 Thanks,

 Ping
 --
 Ping Yang, Ph.D.
 Postdoctoral Research Associate
 CUNY EnVironmental Crossroads Initiative
  
 senani karunaratne
 University of Sydney
 Australia

   [[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] spplot with legend only, and legend inside the plotting area

2012-03-08 Thread Oscar Perpiñán Lamigueiro
Mauricio Zambrano-Bigiarini mauricio.zambr...@jrc.ec.europa.eu writes:

 Thanks Oscar !. I didn't realise about 'latticeExtra' instead of lattice...

 One last question. By using c(), is it possible to put different axis
 labels for each plot ?
 -- START 
 library(sp)
 xyz = data.frame(expand.grid(x=1:10,y=1:10),rnorm(100))
 coordinates(xyz)=~x+y

 # Different spatial extent for the 2nd dummy set
 xyz2 = data.frame(expand.grid(x=100:200,y=100:200),rnorm(10201))
 coordinates(xyz2)=~x+y

 # only to get the default values from 'auto.key'
 dummy - spplot(xyz, cex=2, alpha=0.7, xlab=X1, ylab=Y1,
 scales=list(draw=TRUE))
 dummy2 - spplot(xyz2, cex=2, alpha=0.7, xlab=X2, ylab=Y2)

 # checking that 'dummy' is a trellis
 class(dummy)

 library(lattice)
 library(latticeExtra)
 cObj - c(dummy, dummy2, dummy, dummy2, layout=c(2,4), merge.legends=FALSE)
 update(cObj)

 -- END 

Yes, it is possible. You have to modify the parameters with update:

cObj - c(dummy, dummy2, dummy, dummy2)
update(cObj, xlab=c('X1', 'X2'), ylab.right='Y2')

Best,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] spplot with legend only, and legend inside the plotting area

2012-03-07 Thread Oscar Perpiñán Lamigueiro
Mauricio Zambrano-Bigiarini mauricio.zambr...@jrc.ec.europa.eu writes:

 I need to produce two different spplot figures of spatial points, and
 I would like to ask your help for the creation of the second one:

 1) the first figure has to show the values but without any legend:

 library(sp)
 xyz = data.frame(expand.grid(x=1:10,y=1:10),rnorm(100))
 coordinates(xyz)=~x+y
 spplot(xyz, cex=10, alpha=0.7, auto.key=FALSE)

 (I don't have any problem with this)


 2) The second figure has to show ONLY the legend for the values of the
 previous figure (without plotting the points), inside the plotting
 area.

 I tried with:

 spplot(xyz, cex=0, alpha=0.7, auto.key=TRUE, key.space=center)

Hello,

Try this:

spplot(xyz, auto.key=list(x=.5, y=.5), cex=0)

Change the values of x,y for your convenience. You can also find useful
corner instead of x,y. For more information read the auto.key, key and
legend parts of the help page of xyplot.

Cheers,

Oscar.
-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] spplot with legend only, and legend inside the plotting area

2012-03-07 Thread Oscar Perpiñán Lamigueiro
Mauricio Zambrano-Bigiarini mauricio.zambr...@jrc.ec.europa.eu writes:

 On 07/03/12 13:11, Oscar Perpiñán Lamigueiro wrote:
 Mauricio Zambrano-Bigiarinimauricio.zambr...@jrc.ec.europa.eu  writes:

 The real problem appears when I try to produce several spplots within
 the same figure (each one of them for a different spatial area), with
 a unique legend for all the figures (that is the reason why I can not
 use 'legend' command).

Then you could use c.trellis:

With your example:

c(dummy, dummy, dummy, dummy).

Inside c() you can define the 'layout' and decide if you want to merge
legends with 'merge.legends'.

Oscar.


 sessionInfo() # part of it
 R version 2.14.1 (2011-12-22)
 Platform: x86_64-redhat-linux-gnu (64-bit)
 .
 .
 .

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 other attached packages:
 [1] sp_0.9-95 lattice_0.20-0

 loaded via a namespace (and not attached):
 [1] cluster_1.14.2 grid_2.14.1Hmisc_3.9-2


 Thanks in advance,

 Mauricio Zambrano-Bigiarini

-- 
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Problems with function gplot from rasterVis

2012-02-27 Thread Oscar Perpiñán Lamigueiro
Manuel Spínola mspinol...@gmail.com writes:


 library(raster) library(rasterVis) r = raster(jabali$map) p = gplot(r) + 
 geom_tile(aes(fill = value)) + geom_point(loc, aes(X,Y))Error: ggplot2 
 doesn't know how to deal with data of class uneval

 I can plot the map, but I can get to plot the points on the map.  The
 object loc is a data frame with the locations given by X and Y.

Hi Manuel,

Try this:

gplot(r) + geom_tile(aes(fill = value)) + geom_point(aes(X,Y), data=loc)

The arguments of geom_point are mapping and then data, but you were
using them in reverse order.

Best,

Oscar.

-- 
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Error levelplot+ layer(sp.polygons() +

2012-02-25 Thread Oscar Perpiñán Lamigueiro
Byman bym...@gmail.com writes:

 Could anyone please help me.
 I am plotting raster object (tasc) with 4 seasons: (DJF,MAM, JJA, 
 SON) as layers. I get this raster from an Netcdf file. I would like to 
 add (overlay) the country polygons (afrc) on top of these 4 plots of 
 levelplot.  Levelplot function works quite ok but when I call this plot 
 (p) and plot with layer(sp.polygons(afr)), I get this error:

 Error in get(x, envir = this, inherits = inh)(this, ...) :
Need at least one of stat and geom

[...]
 sessionInfo()
 R version 2.14.1 (2011-12-22)
 Platform: i386-pc-mingw32/i386 (32-bit)
[...]
 other attached packages:
   [1] maps_2.2-5  fts_0.7.7   ggplot2_0.8.9   
 proto_0.3-9.2   reshape_0.8.4
   [6] plyr_1.7.1  ncdf_1.6.6  rasterVis_0.10-9
 hexbin_1.26.0   latticeExtra_0.6-19
 [11] RColorBrewer_1.0-5  raster_1.9-67   maptools_0.8-14 
 lattice_0.20-3  sp_0.9-95
 [16] foreign_0.8-49

 loaded via a namespace (and not attached):
 [1] zoo_1.7-7

Hello,

Both ggplot2 and latticeExtra define a layer function. You have to
call library(latticeExtra) *after* library(ggplot2) to use the
latticeExtra::layer mechanism instead of ggplot2::layer.

Best.

Oscar

-- 
Oscar Perpiñán Lamigueiro
Dpto. de Ingeniería Eléctrica
EUITI-UPM

http://procomun.wordpress.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo