0

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))

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
uncool
  • 2,613
  • 7
  • 26
  • 55
  • 1
    Have you tried this form a clean R environment? It looks like you have have changed things more than just the code shown here. Can you focus on making a more complete [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Right now we can't run this ourselves. Make your sample data reproducible. – MrFlick Aug 03 '15 at 00:57
  • The error is clearly related to the class attribute names. Now I can't recall the function to output raw object data (so I can post the object here). But running the ggplot code inside my main function also generates an error: "ggplot2 doesn't know how to deal with data of class facetindicator " – uncool Aug 03 '15 at 08:39
  • I have both rebuilt and reloaded the package and rebuilt and cleaned the package, both with the same results. – uncool Aug 03 '15 at 09:27
  • 2
    Well the error you mention in your comment is different than the one in the question and is the one I would expect in this situation. You need to coerce your `x` object to a data.frame in the `ggplot.facet` function otherwise ggplot doesn't know what to do with your custom object. – MrFlick Aug 03 '15 at 13:26

0 Answers0