On Tue, 3 Feb 2009, Petr PIKAL wrote:

Hi

[email protected] napsal dne 03.02.2009 09:20:25:

David Scott <d.scott <at> auckland.ac.nz> writes:



I would like to add some vertical lines to a lattice plot of
histograms.
What I am after is a lattice version of abline(v = 1234). The lattice
histogram plot is just:

histogram( ~ LTSE | approach, data = arrivals)


As a little variation on the histogram docs example:

histogram( ~ height | voice.part, data = singer,
          xlab = "Height (inches)", type = "density",
          panel = function(x, ...) {
              panel.histogram(x, ...)
              panel.abline(v= 70)
              panel.mathdensity(dmath = dnorm, col = "black",
                                args = list(mean=mean(x),sd=sd(x)))
          } )



Or if you want add lines at different places in each panel use this
function and set once =T

addLine<- function(a=NULL, b=NULL, v = NULL, h = NULL, ..., once=F) {
tcL <- trellis.currentLayout()
k<-0
for(i in 1:nrow(tcL))
 for(j in 1:ncol(tcL))
   if (tcL[i,j] > 0) {
k<-k+1
       trellis.focus("panel", j, i, highlight = FALSE)
if (once) panel.abline(a=a[k], b=b[k], v=v[k], h=h[k], ...) else
panel.abline(a=a, b=b, v=v, h=h, ...)
       trellis.unfocus()
       }
}

Regards
Petr



Thanks to all respondents, including the first one who answered my question privately, Sundar Dorai-Raj. Sundar's reply was very similar to Dieter's version above and worked for me.

I haven't tried Petr's suggestion, but I had been thinking I probably do
need to put different lines on different panels, so this was a nice bit of
anticipation on his behalf

David Scott _________________________________________________________________
David Scott     Department of Statistics
                The University of Auckland, PB 92019
                Auckland 1142,    NEW ZEALAND
Phone: +64 9 373 7599 ext 85055         Fax: +64 9 373 7018
Email:  [email protected]

Graduate Officer, Department of Statistics
Director of Consulting, Department of Statistics

______________________________________________
[email protected] 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.

Reply via email to