[R] how to add a vertical line for each panel in a lattice dotplot with log scale?

maxbre mbressan at arpa.veneto.it
Mon Jun 11 09:40:10 CEST 2012


sorry but I can't close this thread with a viable solution other than the
following one 
(i.e. by defining an user function to add line);

I understand that the problem is related to the fact that: 
mean(log(.)) != log(mean(.)) is 
but for some reason I can't put all that in practice inside the
panel.abline(...)

I would appreciate if someone can show me how (sorry but at this point I
must give up...),
thank you all for the help


# code start

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() 
      } 
} 



dotplot(date_sampl_time_recs ~ lower_b_i | site, data=teq,
        scales=list(x=list(log=TRUE)),
        xscale.components = xscale.components.logpower,
        layout=c(5,1),
        panel = function(x,y,...) {
          panel.grid(h=53, v=-1, lty="dotted", col="gray")
          panel.dotplot(x,y,...)
          medians <- median(x)
          panel.abline(v=medians, col.line="red", lty="dotted")
          }
        )

medie<-as.vector(tapply(teq$lower_b_i,teq$site,mean))

addLine(v=log10(medie), once=TRUE, col="blue", lty="dotted") 

# code end




--
View this message in context: http://r.789695.n4.nabble.com/how-to-add-a-vertical-line-for-each-panel-in-a-lattice-dotplot-with-log-scale-tp4632513p4632991.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list