[R] Default Display of hist.Date with breaks="months"

Andrews, Chris chrisaa at med.umich.edu
Fri Oct 24 22:11:40 CEST 2014


Hi all,

The default display of random dates with breaks="months" is less than optimal.

set.seed(20141024)
random.dates <- as.Date("2001/1/1") + round(365*stats::runif(100))
hist(random.dates, "months")

The 13 edges of the 12 bars are labelled "Dec", "Jan", "Feb", ..., "Nov", "Dec".
The first bar represents the number of days in January, the label on the RIGHT edge of the bar.

It is clear what is happening if the format is changed.

hist(random.dates, "months", format = "%d %b", las=2)

The labels are now "Dec 31", "Jan 31", "Feb 28", ....  which isn't intuitive to me.

I'd rather have this as the default behavior (but without having to explicitly create the breaks)

hist(random.dates, breaks=as.Date(c(paste("2001",1:12,"1",sep="/"), "2002/1/1")), right=FALSE)
hist(random.dates, breaks=as.Date(c(paste("2001",1:12,"1",sep="/"), "2002/1/1")), right=FALSE, format = "%d %b", las=2)

I guess none of that is a question.  Have a nice weekend.

Chris



R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.1.1

**********************************************************
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 



More information about the R-help mailing list