r - Building own print class method - ggplot2 -
i'm trying build own print method, based on class "facet". want make specific ggplot when calling print, throws me error message
error: ggplot2 doesn't know how deal data of class facetindicator
code
print.facet <- function(x) { print("hello") # print statement gets outputted fine ggplot(data = x, aes( x = published, y = sma90)) + geom_line() } running ggplot manually same object without class attribute works fine. i've must have missed trivial, can be?
you remove facet class when pass object ggplot, or, perhaps more elegantly, via fortify method,
fortify.facet <- function(x) {class(x) <- class(x)[-1]; x} print.facet <- function(x) { ggplot(data = x, aes( x = published, y = sma90)) + geom_line() } d <- data.frame(published=1:10, sma90=1:10) class(d) <- c("facet", class(d)) print(d) you consider defining as.data.frame.facet and/or autoplot methods, may feel more natural.
Comments
Post a Comment