[R] how to add a vertical line for each panel in a lattice dotplot with log scale?
maxbre
mbressan at arpa.veneto.it
Thu Jun 7 16:23:02 CEST 2012
thanks kimmo
I managed to get the desired result by first plotting the medians and then
adding the means through the user defind function posted in thread you
mentioned (here it is
http://r.789695.n4.nabble.com/Adding-mean-line-to-a-lattice-density-plot-td4455770.html#a4456502)
# start
dotplot(variety ~ yield | site, data = barley,
scales=list(x=list(log=TRUE)),
layout = c(1,6),
panel = function(x,y,...) {
panel.dotplot(x,y,...)
median.values <- median(x)
panel.abline(v=median.values, col.line="red")
})
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()
}
}
mean.values<-tapply(barley$yield, barley$site, mean)
addLine(v=log10(mean.values), once=TRUE, col="blue", lty="dotted")
# end
but back to my previous question I still not understand why the plot of
medians is working fine BUT NOT of the means (apparently messing up panel
positions and also values): no clue for this!
I've been trying also with the use of layout() in latticeExtra but without
results...
anyone can clarify me these (strange for me) issues?
max
--
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-tp4632513p4632692.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list