Skip to content

Commit 04cafec

Browse files
committed
Support as.Date() conversion within ggplot code
1 parent 3558668 commit 04cafec

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

R/trace_generation.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,24 @@ layer2traces <- function(l, d, misc) {
4141

4242
## For non-numeric data on the axes, we should take the values from
4343
## the original data.
44-
for (axis.name in c("x", "y")){
45-
if (!misc$is.continuous[[axis.name]]){
44+
for (axis.name in c("x", "y")) {
45+
if (!misc$is.continuous[[axis.name]]) {
4646
aes.names <- paste0(axis.name, c("", "end", "min", "max"))
4747
aes.used <- aes.names[aes.names %in% names(g$aes)]
4848
for(a in aes.used) {
4949
col.name <- g$aes[aes.used]
50-
data.vec <- l$data[[col.name]]
50+
dtemp <- l$data[[col.name]]
51+
if (is.null(dtemp)) {
52+
if (!inherits(g$data[[paste0(a, ".name")]], "NULL")) {
53+
# Handle the case where as.Date() is passed in aes argument.
54+
if (class(g$data[[a]]) != class(g$data[[paste0(a, ".name")]])) {
55+
g$data[[a]] <- g$data[[paste0(a, ".name")]]
56+
data.vec <- g$data[[a]]
57+
}
58+
}
59+
} else {
60+
data.vec <- dtemp
61+
}
5162

5263
# For some plot types, we overwrite `data` with `prestats.data`.
5364
pdata.vec <- misc$prestats.data[[a]]
@@ -274,11 +285,11 @@ toBasic <- list(
274285
g
275286
}
276287
},
277-
path=function(g){
288+
path=function(g) {
278289
group2NA(g, "path")
279290
},
280-
line=function(g){
281-
g$data <- g$data[order(g$data$x),]
291+
line=function(g) {
292+
g$data <- g$data[order(g$data$x), ]
282293
group2NA(g, "path")
283294
},
284295
boxplot=function(g) {
@@ -370,7 +381,7 @@ group2NA <- function(g, geom) {
370381

371382
# Convert basic geoms to traces.
372383
geom2trace <- list(
373-
path=function(data, params){
384+
path=function(data, params) {
374385
list(x=data$x,
375386
y=data$y,
376387
name=params$name,

0 commit comments

Comments
 (0)