Skip to content
Prev 68296 / 398503 Next

Need help with R date handling and barchart with errorbars

On Thursday 21 April 2005 17:44, Ghosh, Sandeep wrote:
Which makes all the columns factors. Odd choice.
No difference (except that the print method for data.frame's doesn't 
know about 'date's.).  Note that you have managed to create dates 
approximately 2000 years in the past.
If all you want is the dates in the right order, you could do:

testdata$date <- factor(testdata$date, levels = testdata$date)
The S language encourages the user to program the little things that are 
not readily available. In this case (making a guess about what sort of 
error bar you want):


with(testdata, 
     barchart(date ~ as.numeric(as.character(mean)) | dataset,
              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]
                  panel.segments(x - sd / sqrt(count),
                                 as.numeric(y),
                                 x + sd / sqrt(count),
                                 as.numeric(y),
                                 col = 'red', lwd = 2)
              }))


which would have been more readable if everything in your data frame 
were not factors. (It's none of my business, but I think dotplots would 
be a better choice than barcharts if you want to add error bars.)

Deepayan