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

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Wed 04 Apr 2007 - 15:15:40 GMT

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@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



R-help@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. Received on Thu Apr 05 01:26:40 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 18:30:56 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.