@@ -234,17 +234,20 @@ gg2list <- function(p){
234
234
# # what ggplot_build gives us).
235
235
misc <- list ()
236
236
for (a in c(" fill" , " colour" , " x" , " y" )){
237
- fun.name <- sprintf(" scale_%s_continuous" , a )
238
- fun <- get(fun.name )
239
- misc $ is.continuous [[a ]] <- tryCatch({
240
- suppressMessages({
241
- with.scale <- p + fun()
237
+ for (data.type in c(" continuous" , " date" , " datetime" , " discrete" )){
238
+ fun.name <- sprintf(" scale_%s_%s" , a , data.type )
239
+ misc.name <- paste0(" is." , data.type )
240
+ misc [[misc.name ]][[a ]] <- tryCatch({
241
+ fun <- get(fun.name )
242
+ suppressMessages({
243
+ with.scale <- p + fun()
244
+ })
245
+ ggplot2 :: ggplot_build(with.scale )
246
+ TRUE
247
+ }, error = function (e ){
248
+ FALSE
242
249
})
243
- ggplot2 :: ggplot_build(with.scale )
244
- TRUE
245
- }, error = function (e ){
246
- FALSE
247
- })
250
+ }
248
251
}
249
252
250
253
# # scales are needed for legend ordering.
@@ -329,8 +332,12 @@ gg2list <- function(p){
329
332
ax.list $ titlefont <- theme2font(title.text )
330
333
ax.list $ type <- if (misc $ is.continuous [[xy ]]){
331
334
" linear"
332
- }else { # # TODO: time scales?
335
+ }else if ( misc $ is.discrete [[ xy ]]){
333
336
" category"
337
+ }else if (misc $ is.date [[xy ]] || misc $ is.datetime [[xy ]]){
338
+ " date"
339
+ }else {
340
+ stop(" unrecognized data type for " , xy , " axis" )
334
341
}
335
342
# # Lines drawn around the plot border:
336
343
ax.list $ showline <- ifelse(is.blank(" panel.border" ), FALSE , TRUE )
@@ -373,15 +380,19 @@ layer2traces <- function(l, d, misc){
373
380
# # needed for when group, etc. is an expression.
374
381
g $ aes <- sapply(l $ mapping , function (k ) as.character(as.expression(k )))
375
382
376
- # # For factors on the axes, we should take the values from the
377
- # # original data.
383
+ # # For non-numeric data on the axes, we should take the values from
384
+ # # the original data.
378
385
for (axis.name in c(" x" , " y" )){
379
386
if (! misc $ is.continuous [[axis.name ]]){
380
387
aes.names <- paste0(axis.name , c(" " , " end" , " min" , " max" ))
381
388
aes.used <- aes.names [aes.names %in% names(g $ aes )]
382
- if (length(aes.used )){
383
- col.used <- g $ aes [aes.used ]
384
- g $ data [aes.used ] <- l $ data [col.used ]
389
+ for (a in aes.used ){
390
+ col.name <- g $ aes [aes.used ]
391
+ data.vec <- l $ data [[col.name ]]
392
+ if (inherits(data.vec , " POSIXt" )){
393
+ data.vec <- strftime(data.vec , " %Y-%m-%d %H:%M:%S" )
394
+ }
395
+ g $ data [[a ]] <- data.vec
385
396
}
386
397
}
387
398
}
0 commit comments