Skip to content
Prev 69220 / 398506 Next

Need some quick help with lattice - barchart

Ghosh, Sandeep wrote on 5/5/2005 11:10 AM:
Hi Sandeep,

First, you are overusing as.numeric and as.character. Is there a reason 
for this that the example doesn't demonstrate.

Second, scales$y$limits is the same as setting ylim. The latter is more 
readable in my opinion.

As to your actual question, you should supply a scales argument for the 
x-axis. Below is what I came up with:

barchart(mean ~ month | year, data = testdata,
          layout = c(1, nlevels(testdata$year)),
          horizontal = FALSE,
          ylim = c(1, max(testdata$mean) + max(testdata$stdDev)),
          main = 'Marble Burying - Level I',
          xlab = 'Months',
          ylab = 'Mean',
          sd = testdata$stdDev,
          scales = list(x = list(at = 1:7,
                          labels = unique(sort(testdata$month)))),
          panel = function(x, y, ..., sd, subscripts) {
            panel.barchart(x, y, ...)
            sd <- sd[subscripts]
            panel.segments(x, y - sd, x, y + sd, col = 'red', lwd = 2)
          })


HTH,

--sundar