ggExtra icon indicating copy to clipboard operation
ggExtra copied to clipboard

ggMarginal can’t handle Date axes

Open flying-sheep opened this issue 8 years ago • 2 comments

library(ggExtra)
data(airquality)
airquality$Date <- with(airquality, as.Date(sprintf('1973-%02d-%02d', Month, Day)))

p <- ggplot(airquality, aes(Date, Temp)) + geom_point()
print(ggMarginal(data = airquality, x = 'Date', y = 'Temp'))  # works
print(ggMarginal(p, airquality, 'Date'))                      # doesn’t

the second one throws:

Error: Invalid input: date_trans works with objects of class Date only
Traceback:

1. print(ggMarginal(p, airquality, "Date"))
2. ggMarginal(p, airquality, "Date")
3. ggplot2::ggplot_build(top)
4. lapply(data, scales_transform_df, scales = scales)
5. FUN(X[[i]], ...)
6. unlist(lapply(scales$scales, function(s) s$transform_df(df = df)), 
 .     recursive = FALSE)
7. lapply(scales$scales, function(s) s$transform_df(df = df))
8. FUN(X[[i]], ...)
9. s$transform_df(df = df)
10. f(..., self = self)
11. lapply(df[aesthetics], self$transform)
12. FUN(X[[i]], ...)
13. f(..., self = self)
14. self$trans$transform(x)
15. stop("Invalid input: date_trans works with objects of class Date only", 
  .     call. = FALSE)

flying-sheep avatar Mar 24 '17 13:03 flying-sheep

Thank you for the report. ggExtra is currently undergoing major revisions and hopefully this will be solved in the next version

daattali avatar Mar 26 '17 23:03 daattali

I looked into this and it's only easy to fix it for the top marginal plot. I believe you would have to go deep into the internals of ggplot2 to get it working for both top and right marginal plots.

crew102 avatar May 15 '17 17:05 crew102