baptiste auguie
2010-May-18 13:02 UTC
[R] lattice::panel.levelplot.raster too picky with unequal spacing
Dear all, I got a couple of warnings using panel.levelplot.raster, In panel.levelplot.raster(..., interpolate = TRUE) : 'y' values are not equispaced; output will be wrong although I was quite sure my data were equally spaced (indeed, I created them with seq()). A closer look at the source code reveals that the function tests for exact uniformity in grid spacing, if (length(unique(diff(uy))) != 1) warning("'x' values are not equispaced; output will be wrong") The following dummy example would suggest that a strict equality is not always suitable, x <- seq(0, 50, length=100) ux <- sort(unique(x[!is.na(x)])) length(unique(diff(ux))) # 8 sd(unique(diff(ux))) # 2.462951e-15 Suggestions / comments are welcome. Best regards, baptiste sessionInfo() R version 2.11.0 RC (2010-04-16 r51754) i386-apple-darwin9.8.0 locale: [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.18-5 loaded via a namespace (and not attached): [1] grid_2.11.0 tools_2.11.0 -- ____________________ Baptiste Augui? Departamento de Qu?mica F?sica, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides
Deepayan Sarkar
2010-May-18 13:30 UTC
[R] lattice::panel.levelplot.raster too picky with unequal spacing
On Tue, May 18, 2010 at 6:32 PM, baptiste auguie <baptiste.auguie at googlemail.com> wrote:> Dear all, > > I got a couple of warnings using panel.levelplot.raster, > > In panel.levelplot.raster(..., interpolate = TRUE) : > ?'y' values are not equispaced; output will be wrong > > although I was quite sure my data were equally spaced (indeed, I > created them with seq()). A closer look at the source code reveals > that the function tests for exact uniformity in grid spacing, > > ?if (length(unique(diff(uy))) != 1) > ? ? ? ? ? ?warning("'x' values are not equispaced; output will be wrong")Maybe a better test would be isTRUE(all.equal(diff(range(diff(ux))), 0)) I'll try that out for the next release. -Deepayan> > The following dummy example would suggest that a strict equality is > not always suitable, > > x <- seq(0, 50, length=100) > ux <- sort(unique(x[!is.na(x)])) > length(unique(diff(ux))) > # 8 > sd(unique(diff(ux))) > # ?2.462951e-15 > > Suggestions / comments are welcome. > > Best regards, > > baptiste > > > sessionInfo() > R version 2.11.0 RC (2010-04-16 r51754) > i386-apple-darwin9.8.0 > > locale: > [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8 > > attached base packages: > [1] stats ? ? graphics ?grDevices utils ? ? datasets ?methods ? base > > other attached packages: > [1] lattice_0.18-5 > > loaded via a namespace (and not attached): > [1] grid_2.11.0 ?tools_2.11.0 > > > > -- > ____________________ > > Baptiste Augui? > > Departamento de Qu?mica F?sica, > Universidade de Vigo, > Campus Universitario, 36310, Vigo, Spain > > tel: +34 9868 18617 > http://webs.uvigo.es/coloides > ____________________ > >