简体   繁体   中英

Boxplot{car} for Date variables (R)

I rerun a R-program written 1 month ago on the same dataset, involving boxplots of date variables by the Boxplot function of the car package to label outliers (which I did not manage to do with the generic boxplot). The same program on the same dataset now gives as error:

Error in seq.Date(along = y) : 'from' must be specified

Here a minimal example:

x<-as.Date(c("1992-01-01", "2011-04-06", "2010-09-30", "2001-04-11", "1996-03-12"))
Boxplot(x)

(boxplot(x) works perfectly - but I didnot manage to label the outliers by ID in my dataframe).

Apart from the specific problem: how come a program runs perferctly on a dataset in August and the identical program on the identical dataset fails to do so in September? I wrote it as an .rnw - File - so there cannot be a difference in the packages loaded.

Ok - found a workaround myself by converting the dates into numerics and back for the axis - labelling:

 x<-as.Date(c("1992-01-01", "2019-04-06", "1990-09-30", "2001-04-11", "1996-03-12"))
 yticks<-c("1990-01-01","2000-01-01","2010-01-01","2020-01-01" )
 yticklocs<-as.numeric(as.Date(yticks))
 Boxplot(as.numeric(x),ylim=as.numeric(as.Date(c("1990-01-01","2020-01-01"))),yaxt="n")
axis(2,labels=year(as.Date(yticks)),at=yticklocs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM