[R] Odp: Separate ablines in lattice panels
Petr PIKAL
petr.pikal at precheza.cz
Wed Jan 18 06:21:06 CET 2012
Hi
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()
}
}
after making a lattice plot just use
addLine(v=vector of values where you want to plot a line in each panel,
once =TRUE)
Regards
Petr
>
> Searched archives and found some old email threads on the topic. But mot
> exactly what I think I need. Suppose I have a datafile such as tmp.
>
> tmp <- data.frame(var1 = c(rnorm(1000), rnorm(1000, 1, 1)), var2 = gl(2,
1000))
>
> I'd like a plot similar to the one below, but with an abline of v=0 in
the
> lower panel and v=1 in the upper panel. Code below creates two lines in
> each panel, not quite sure how to separate them by panel.
>
> densityplot(~ var1|var2, tmp,
> type = c('g', 'l'),
> layout = c(1,2),
> panel = function(x, ...){
> panel.densityplot(x, ...)
> panel.abline(v = c(0,1))
> }
> )
>
> Thank you
> Harold
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list