我有一个data.frame对象,ggplot2在函数中输出正常。但是当我尝试通过类方法输出它时它不起作用。
现在我试图通过在ggplot函数调用中添加UseMethod来扩展ggplot。据我了解,由于命名空间,这不应该是一个问题。那有什么不对呢?
代码
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 ~ .)
}
我的目标是推送到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
我的通话和错误消息
> 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))