@@ -234,17 +234,20 @@ gg2list <- function(p){
234234 # # what ggplot_build gives us).
235235 misc <- list ()
236236 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
242249 })
243- ggplot2 :: ggplot_build(with.scale )
244- TRUE
245- }, error = function (e ){
246- FALSE
247- })
250+ }
248251 }
249252
250253 # # scales are needed for legend ordering.
@@ -329,8 +332,12 @@ gg2list <- function(p){
329332 ax.list $ titlefont <- theme2font(title.text )
330333 ax.list $ type <- if (misc $ is.continuous [[xy ]]){
331334 " linear"
332- }else { # # TODO: time scales?
335+ }else if ( misc $ is.discrete [[ xy ]]){
333336 " category"
337+ }else if (misc $ is.date [[xy ]] || misc $ is.datetime [[xy ]]){
338+ " date"
339+ }else {
340+ stop(" unrecognized data type for " , xy , " axis" )
334341 }
335342 # # Lines drawn around the plot border:
336343 ax.list $ showline <- ifelse(is.blank(" panel.border" ), FALSE , TRUE )
@@ -373,15 +380,19 @@ layer2traces <- function(l, d, misc){
373380 # # needed for when group, etc. is an expression.
374381 g $ aes <- sapply(l $ mapping , function (k ) as.character(as.expression(k )))
375382
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.
378385 for (axis.name in c(" x" , " y" )){
379386 if (! misc $ is.continuous [[axis.name ]]){
380387 aes.names <- paste0(axis.name , c(" " , " end" , " min" , " max" ))
381388 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
385396 }
386397 }
387398 }
0 commit comments