[R] how to add a vertical line for each panel in a lattice dotplot with log scale?
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Jun 15 11:17:54 CEST 2012
On Mon, Jun 11, 2012 at 1:10 PM, maxbre <mbressan at arpa.veneto.it> wrote:
> 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...),
I'm not sure why this is difficult. Once you realize that your problem
was in taking mean of the log-transformed values instead of the
original values, all you need to do is transform back to the original
scale, compute mean, and transform back.
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,...)
panel.abline(v = median(x), col.line="red", lty="dotted")
panel.abline(v = log10(mean(10^x)), col.line="blue", lty="dotted")
}
)
-Deepayan
> 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.
>
> ______________________________________________
> 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