plotlyR子图错误在图[[i]] [[“frames”]]:下标超出界限

时间:2018-01-19 09:49:34

标签: r plotly

我正在使用R 3.4.2与包图形版本'4.7.1'

我首先准备这个情节(有效):

x = structure(c(1444262400, 1444348800, 1444608000, 1444694400, 1444780800, 
            1444867200, 1444953600, 1445212800, 1445299200, 1445385600, 1445472000, 
            1445558400, 1445817600, 1445904000, 1445990400, 1446076800, 1446163200
), tzone = "GMT", tclass = c("POSIXct", "POSIXt"), class = c("POSIXct", 
                                                             "POSIXt"))

y = c(-68.1377966700034, -68.5283603030953, -68.533877757571, -66.7349127872575, 
      -66.0681953259191, -67.6301142574414, -69.6710392385029, -70.170692866109, 
      -70.0701763503189, -71.9537057278669, -72.0177423408879, -68.300778528265, 
      -68.559662880874, -68.5621379677293, -69.2857358836203, -73.4822677099078, 
      -75.3170151811821)

p = plotly::plot_ly(x = x, y = y, type = "scatter", mode = "lines", line=list(dash = NULL), name = "margin", visible = NULL) %>% 
  plotly::layout(xaxis = NULL, yaxis = list(type = "linear", title=NULL), title="margin", legend = NULL, shapes = NULL)

但是下面的子图不起作用!

plotly::subplot(p, p, nrow=2, shareX = TRUE)

我收到此错误:Error in plots[[i]][["frames"]] : subscript out of bounds

你得到同样的错误吗?

2 个答案:

答案 0 :(得分:3)

正如@MLavoie评论的那样,它只是s参数末尾缺少的nrow。我有同样的问题,错误信息令人困惑,错误是令人尴尬的简单。

答案 1 :(得分:0)

只是一个贡献(我把它作为一个答案,因为我没有评论的权利)。

我在子图中拼错了另一个选项时遇到了这个错误。我写了 shareX 而不是 sharedX,发现同样的错误 Error in plots[[i]][["frames"]] : subscript out of bounds

正确的拼写是:

subplot(f1,g,g2, nrows = 3, shareX = TRUE)