[R] help with plotting a grid on levelplot
Deepayan Sarkar
deepayan at stat.wisc.edu
Wed Mar 30 05:21:33 CEST 2005
On Tuesday 29 March 2005 19:16, Jeff D. Hamann wrote:
> I'm trying to plot a grid over a levelplot
>
> print( levelplot( var1.pred~x+y,
> data=saw.pred,
> aspect=mapasp(saw.pred),
> col.regions=terrain.colors(80),
> main=main) )
>
> using the data...
>
> > saw.pred
>
> x y var1.pred var1.var sort
> 1 5 5 3.3761200 256.3363 saw
> 2 15 5 3.3884142 499.5695 saw
> 3 25 5 3.5394769 362.5490 saw
> 4 35 5 3.6386983 439.3200 saw
> 5 45 5 3.1866799 458.5570 saw
> 6 55 5 2.8838555 331.2363 saw
> ..blah...blah...blah...
> 15 145 5 0.8705088 256.3363 saw
> 16 5 15 3.1183053 455.3765 saw
> 17 15 15 3.2780465 443.1954 saw
> 18 25 15 3.7146268 435.1166 saw
>
> which looks just fine. I know want to plot a grid such that the cells
> are grouped into 5x5 cells (or some other grid spacing) over the
> levelplot for a demonstration and I'm getting stuck when trying to
> modify my levelplot() call above to include the extra calls to
> panel.levelplot...
>
> I've gotten this far,
>
> ## plot the results (10mx10m plot that's 150m x 200m)
> main=expression( paste( widehat(V)[saw], ", in ", m^3, ha^{-1} ) )
> print( levelplot( var1.pred~x+y,
> data=saw.pred,
> aspect=mapasp(saw.pred),
> main=main,
> panel = function(x,y,z=var1.pred )
> {
> panel.levelplot( x=x, y=y, z=z,
> subscripts=1:nrow(saw.pred),
> col.regions=terrain.colors(80),
> )
> panel.last=grid( 15, 20, lwd=2, lty="solid",
> col="black" )
You are not allowed to use base graphics functions (like grid) in
lattice panel functions. You have to use grid (the package, not the
function) functions. There are many such functions defined in lattice
which can be useful, in this case 'panel.grid' or more likely
'panel.abline'.
I'm not sure I understand your attempted usage though; you seem to
assign the value of grid() (which would be NULL) to a variable called
panel.last. This does not have any possible use that I can see.
> }
> ) )
>
> and the legend does match the same colors as the levelplot and the
> grid isn't centered on the levelplot either.
>
> Could someone give me some direction? I've stayed away from modifying
> the panel.XX args when I use lattice, and now I need help.
Unless you understand very well what you are doing, I would stay away
from micro-managing calls to complicated panel functions like
panel.levelplot. In particular, I would suggest something like
panel = function(...) {
panel.levelplot(...)
panel.abline(h=<whatever>, v=<whatever>)
}
> Thanks,
> Jeff.
>
> ---
> Jeff D. Hamann
> Forest Informatics, Inc.
> PO Box 1421
> Corvallis, Oregon USA 97339-1421
> 541-754-1428
> jeff.hamann at forestinformatics.com
> www.forestinformatics.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list