我正在使用(http://ggplot2.tidyverse.org/reference/geom_density_2d.html#computed-variables)的示例来生成密度图。但是,我有以下错误:
library(ggplot2)
library(raster)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
d <- ggplot(dsmall, aes(x, y))
d + stat_density_2d(geom = "raster", aes(fill = calc(density)), contour = FALSE)
# Error in (function (classes, fdef, mtable) :
# unable to find an inherited method for function ‘calc’ for signature
# ‘"standardGeneric", "missing"’
我错过了什么吗? density
是否有一些预先计算的对象?
有人可以帮忙吗?