r - 为什么在 hexbin 对象上调用 graphics::plot 会引发错误?
问题描述
简而言之:我正在尝试运行这个 hexbin 示例,除非我替换plot
为graphics::plot
. 后者引发以下错误:
> graphics::plot(bin, main="" , colramp=my_colors , legend=F )
Error in as.double(y) :
cannot coerce type 'S4' to vector of type 'double'
如何使这项工作?
更广泛的背景为什么我需要以这种方式工作。我为使用 RServe 将 R 引入 Clojure的clojisr 项目做出了贡献。有一个选项可以要求 R 包并创建相应的 Clojure 函数。这很好用(见this或this)。对 R 的底层调用以{package::symbol}
for Everything 的形式出现。
解决方案
Classhexbin
是一个 S4 类,包定义了一个 S4 泛型和一个用于plot
. (源代码在这里)。plot
包命名空间中没有 S4 泛型graphics
,只有 S3 泛型。
因此解决方案非常简单:
hexbin::plot(bin, main="" , colramp=my_colors , legend=F )
这是一个证明它的代表:
library(hexbin)
library(RColorBrewer)
# Create data
x <- rnorm(mean=1.5, 5000)
y <- rnorm(mean=1.6, 5000)
# Make the plot
bin<-hexbin(x, y, xbins=40)
my_colors=colorRampPalette(rev(brewer.pal(11,'Spectral')))
hexbin::plot(bin, main="" , colramp=my_colors , legend=F )
由reprex 包于 2020-02-17 创建(v0.3.0)
推荐阅读
- excel - 尽管通过 VBA 打开代码,但仍然遇到“编译错误:找不到方法或数据成员”
- javascript - Google Sheets 脚本优化 - 避免最长执行时间
- python - python - 排列带有链接列的excel文件
- php - single.php 上的 Echo 作者头像
- sql - 当 SELECT 子句中存在 ISNULL 时,如何舍入值中的小数?
- java - 是否可以使用 ByteBuddy Advice 机制将本机方法封装在线程中?
- java - 有没有办法从 Kafka 消息中读取任意 JSON 并将该任意 JSON 作为相同内容的 Kafka 消息转发?
- mysql - 数据未推送到 mysql 表中
- amazon-web-services - AWS - 调用 GetObject 操作时发生错误 (AccessDenied):访问被拒绝
- windows - 如何在 Windows 上安装 Humhub