I have an data.frame
object which ggplot2
outputs fine when in a function. But when I try to output it through a class method it doesn't work.
Now I'm trying to extend the ggplot by adding UseMethod inside a ggplot
function call. As I understand it, this should not be an issue due to namespacing. So what can be wrong?
Code
ggplot <- function (x) {
UseMethod("ggplot", x)
}
ggplot.facet <- function(x) {
print("hello")
ggplot2::ggplot(x, aes( x = published, y = SMA90)) + geom_line() + facet_grid(areaSize ~ .)
}
My object I push to ggplot
> class(x)
[1] "facet" "indicator"
> summary(x)
Length Class Mode
listPrice 34764 -none- numeric
rent 34764 -none- numeric
floor 34764 -none- numeric
livingArea 34764 -none- numeric
rooms 34764 -none- numeric
published 34764 Date numeric
constructionYear 34764 -none- numeric
objectType 34764 -none- character
booliId 34764 -none- numeric
soldDate 34764 Date numeric
soldPrice 34764 -none- numeric
url 34764 -none- character
isNewConstruction 34764 -none- numeric
additionalArea 34764 -none- numeric
location.namedAreas 34764 factor numeric
location.address.streetAddress 34764 -none- character
location.position.latitude 34764 -none- numeric
location.position.longitude 34764 -none- numeric
location.region.municipalityName 34764 -none- character
location.region.countyName 34764 -none- character
location.distance.ocean 34764 -none- numeric
source.name 34764 -none- character
source.id 34764 -none- numeric
source.type 34764 -none- character
source.url 34764 -none- character
areaSize 34764 factor numeric
priceDiff 34764 -none- numeric
perc.priceDiff 34764 -none- numeric
SMA90 34764 -none- numeric
My call and error message
> ggplot(x)
[1] "hello"
Show Traceback
Rerun with Debug
Error in ggplot.facet(x, aes(x = x$published, y = x$SMA90)) : unused argument (aes(x = x$published, y = x$SMA90))