[R] Annotate a levelplot (using abline) - Difficulty with trellis.

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Apr 4 17:15:40 CEST 2007



Dan Bolser said the following on 4/4/2007 7:52 AM:
> My question was thus;
> 
> Given
> 
>   library(lattice)
>   my.m <- matrix(seq(1,100,1),nrow=10)
>   levelplot(my.m)
> 
> 
> How can I add a diagonal line onto the resulting 'color square'?
> 
> The answer I found was to hack the 'panel.levelplot' function. Here is the
> diff between the old (panel.levplot) and the new (my.panel.levplot)
> functions;
> 
> ***************
> *** 72,77 ****
> --- 82,89 ----
>                     shrinky[2], fullZrange), default.units = "native",
>                   gp = gpar(fill = col.regions[zcol], lwd = 1e-05,
>                     col = "transparent", alpha = alpha.regions))
> +     ## Added by Dan
> +     panel.abline(0,1,col="white")
>       if (contour) {
>         if (is.logical(labels) && !labels)
>           labels <- NULL
> 
> 
> And then use...
> 
>   library(lattice)
>   my.m <- matrix(seq(1,100,1),nrow=10)
>   levelplot(my.m, panel=my.panel.levelplot)
> 
> 
> I accidentally started to talk to Charilaos Skiadas 'off-list', so thanks to
> him for help.
> 
> Dan.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.


Hi, Dan,

This can be more easily done using the following:

library(lattice)
my.m <- matrix(seq(1, 100, 1), nrow = 10)
my.panel.levelplot <- function(...) {
   panel.levelplot(...)
   panel.abline(0, 1, col = "white")
}
levelplot(my.m, panel = my.panel.levelplot)


HTH,

--sundar



More information about the R-help mailing list