Skip to content
Prev 305693 / 398506 Next

Boxplot lattice vs standard graphics

Hello,

Em 17-09-2012 18:50, David Winsemius escreveu:
Actually there is, in the op.
And since I'm terrible at graphics I try to learn as much as possible on 
R-Help. Here it goes.


library(lattice)

test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"), conc = c(2.32, 0.902,
0.468, 5.51, 1.49, 0.532, 0.72, 0.956, 0.887, 20, 30, 2.12, 0.442,
10, 50, 110, 3.36, 2.41, 20, 70, 3610, 100, 4.79, 20, 0.0315,
30, 60, 1, 3.37, 80, 1.21, 0.302, 0.728, 1.29, 30, 40, 90, 30,
0.697, 6.25, 0.576, 0.335, 20, 10, 620, 40, 9.98, 4.76, 2.61,
3.39, 20, 4.59)), .Names = c("site", "conc"), row.names = c(NA,
52L), class = "data.frame")


#standard graphics
dev.new()
with(test,boxplot(conc~site, log="y"))

#lattice
mystats <- function(x, ...){ # Here ...
     out <- boxplot.stats(10^x, ...)  # ...and here!!!
     out$stats <- log10(out$stats)
     out$conf <- log10(out$conf) ## Omit if you don't want notches
     out$out <- log10(out$out)
     out ## With the boxplot statistics converted to the log10 scale
}

dev.new()
bwplot(conc~site, data=test,
        scales = list(y=list(log=10)),
        panel = function(...){
          panel.bwplot(..., stats = mystats)
        }
)

With a median _line_ it would be perfect.
(Not a follow-up, it was already answered some time ago, use pch = "|" 
in panel.bwplot.)

Rui Barradas