使用 plotly 时出错“方法签名 (2) 中的元素多于函数‘asJSON’的通用签名 (1) 中的元素”
error using plotly " more elements in the method signature (2) than in the generic signature (1) for function ‘asJSON’"
我这里的错误类似于, but I couldn't understand how to use the solution for that post for my situation.- I am using xtabs to convert data in columns to a matrix for a plotly surface plot as per this。在真实的 df 中,第二列中有多个值(数据集是使用 expand.grid 创建的,以获得一些模型预测)。
一个例子:
df <- read.table(text =
"WtavR WcsavR pred
1 18.62672 0.03825 0.6113332
2 18.73131 0.03825 0.6079856
3 18.83590 0.03825 0.6046379
4 18.94049 0.03825 0.6012903
5 19.04508 0.03825 0.5979427
6 19.14967 0.03825 0.5945950
7 19.25426 0.03825 0.5912474
8 19.35885 0.03825 0.5878998
9 19.46344 0.03825 0.5845521
10 19.56803 0.03825 0.5812045
11 19.67262 0.03825 0.5778568
12 19.77721 0.03825 0.5745092
13 19.88180 0.03825 0.5711616
14 19.98639 0.03825 0.5678139
15 20.09098 0.03825 0.5644663
16 20.19557 0.03825 0.5611187
17 20.30016 0.03825 0.5577710
18 20.40475 0.03825 0.5544234
19 20.50934 0.03825 0.5510758
20 20.61393 0.03825 0.5477281", header = T)
p6 <- plot_ly(z = ~xtabs(pred ~ WtavR + WcsavR, data = df)) %>% add_surface()
p6
这会产生以下错误
Error in matchSignature(signature, fdef) :
more elements in the method signature (2) than in the generic signature (1) for function ‘asJSON’
如有任何帮助,我将不胜感激。我只是在模型预测的表面图之后。
xtabs()
生成 class xtabs
的对象而不是普通矩阵。
通过删除 class,我发现我可以让 plotly
表现:
df <- expand.grid(x=0:9, y=0:9) %>% mutate(z=x*y)
surface <- unclass(xtabs(z ~ x + y, data = df))
plot_ly(z = ~surface) %>% add_surface()
我这里的错误类似于
一个例子:
df <- read.table(text =
"WtavR WcsavR pred
1 18.62672 0.03825 0.6113332
2 18.73131 0.03825 0.6079856
3 18.83590 0.03825 0.6046379
4 18.94049 0.03825 0.6012903
5 19.04508 0.03825 0.5979427
6 19.14967 0.03825 0.5945950
7 19.25426 0.03825 0.5912474
8 19.35885 0.03825 0.5878998
9 19.46344 0.03825 0.5845521
10 19.56803 0.03825 0.5812045
11 19.67262 0.03825 0.5778568
12 19.77721 0.03825 0.5745092
13 19.88180 0.03825 0.5711616
14 19.98639 0.03825 0.5678139
15 20.09098 0.03825 0.5644663
16 20.19557 0.03825 0.5611187
17 20.30016 0.03825 0.5577710
18 20.40475 0.03825 0.5544234
19 20.50934 0.03825 0.5510758
20 20.61393 0.03825 0.5477281", header = T)
p6 <- plot_ly(z = ~xtabs(pred ~ WtavR + WcsavR, data = df)) %>% add_surface()
p6
这会产生以下错误
Error in matchSignature(signature, fdef) : more elements in the method signature (2) than in the generic signature (1) for function ‘asJSON’
如有任何帮助,我将不胜感激。我只是在模型预测的表面图之后。
xtabs()
生成 class xtabs
的对象而不是普通矩阵。
通过删除 class,我发现我可以让 plotly
表现:
df <- expand.grid(x=0:9, y=0:9) %>% mutate(z=x*y)
surface <- unclass(xtabs(z ~ x + y, data = df))
plot_ly(z = ~surface) %>% add_surface()