Skip to content
Prev 68500 / 398506 Next

Need help with panel.segment..

On Mon, 2005-04-25 at 11:13 -0500, Ghosh, Sandeep wrote:
<snip>

The original code that Deepayan provided to you did not have 'horizontal
= FALSE' in the barchart() call.

Thus, by including that in yours, you rotated the chart 90 degrees,
which means that you need to alter the panel.segments call to reflect
that change by transposing the x and y values:

trellis.par.set(theme = col.whitebg())
with(testdata, 
     barchart(mean ~ month | year,
              horizontal=FALSE,
              layout=c(1,2),
              origin = 0,
              sd = as.numeric(as.character(stdDev)),
              count = as.numeric(as.character(miceCount)),
              panel = function(x, y, ..., sd, count, subscripts) {
                  panel.barchart(x, y, ...)
                  sd <- sd[subscripts]
                  count <- count[subscripts]

 # NOTE THE CHANGE HERE
                  panel.segments(as.numeric(x),
                                 y - sd / sqrt(count),
                                 as.numeric(x),
                                 y + sd / sqrt(count),
                                 col = 'red', lwd = 2)
              }))

HTH,

Marc Schwartz