Skip to content

lattice dotplot labelling median and mean values for each panel

3 messages · Massimo Bressan

#
By considering this reproducible example

#start code
library(lattice)

dotplot(variety ~ yield | site, data = barley, 
        layout = c(1,6),
        index.cond= function(x,y){median(x)},
        panel = function(x,y,...) { 
          panel.dotplot(x,y,...) 
          median.values <- median(x) 
          panel.abline(v=median.values, col.line="red")
          mean.values<-mean(x)
          panel.abline(v=mean.values, col.line="blue")
          #panel.text()  #?
        }) 

#end code

I would like to add a label showing respectively the median (red vertical
line) and the mean (blue vertical line)  for each panel and possibly tweak
the label positions so that they do not overlap;
I think to understand it has something to do with panel.text() but I can?t
properly set it to work: any help for this?

thanks

max




--
View this message in context: http://r.789695.n4.nabble.com/lattice-dotplot-labelling-median-and-mean-values-for-each-panel-tp4658900.html
Sent from the R help mailing list archive at Nabble.com.
#
sorry, I've managed to find a (partial) solution to my problem (even not much
elegant);
now what is left out is the proper tweaking of labels...

any better solutions?

dotplot(variety ~ yield | site, data = barley, 
        layout = c(1,6),
        index.cond= function(x,y){median(x)},
        panel = function(x,y,...) { 
          panel.dotplot(x,y,...) 
          median.values <- median(x) 
          panel.abline(v=median.values, col.line="red")
          mean.values<-mean(x)
          panel.abline(v=mean.values, col.line="blue")
          panel.text(x=median.values,y=mean(as.numeric(y)),
labels=round(median.values,0),col="red",pos=1,...)
          panel.text(x=mean.values,y=mean(as.numeric(y)),
labels=round(mean.values,0),col="blue",pos=1,...)
          })



--
View this message in context: http://r.789695.n4.nabble.com/lattice-dotplot-labelling-median-and-mean-values-for-each-panel-tp4658900p4658912.html
Sent from the R help mailing list archive at Nabble.com.
#
sorry again, there is something more to consider...

in case I need to plot x axis in logarithmic scale the above solution is not
working:
so now my further question is how to do that when I set
scales=list(x=list(log=TRUE))

I've been trying to simplify my original example to the bare bone  (for sake
of simplicity) but leaving out something (log scaling) that turned out to be
an essential feature to get my final result 

thanks
max






--
View this message in context: http://r.789695.n4.nabble.com/lattice-dotplot-labelling-median-and-mean-values-for-each-panel-tp4658900p4658914.html
Sent from the R help mailing list archive at Nabble.com.