【发布时间】:2020-09-23 11:47:31
【问题描述】:
这里是初学者,所以请温柔! ;)
我在 R 中使用plotly 来生成一些数字。
代码直接在脚本中运行时运行良好,但当我尝试从函数输出plotly 图形时失败。
例如,输入以下内容并直接运行显示图形并且工作正常(data 是一个包含许多不同参数的列表):
fig1 <- plot_ly(x = 0:100, y = data[[parameter]], type = 'scatter', mode = 'lines', line = list(color = 'rgba(191,191,191,0.2)'))
fig1
我有很多情节要做,所以做了如下函数:
Special_plot <- function(data, parameter){fig1 <- plot_ly(x = 0:100, y = data[[parameter]], type = 'scatter', mode = 'lines', line = list(color = 'rgba(191,191,191,0.2)'))
return(fig1)
}
函数运行,但在显示图形时,我收到一条错误消息:
fig1 <- Special_plot(data, parameter)
fig1
这是错误信息:
Error: Tibble columns must have consistent lengths, only values of length one are recycled:
* Length 0: Column `y`
* Length 101: Column `x`
Run `rlang::last_error()` to see where the error occurred.
我有很多数字要处理,并且希望避免单独输入每个数字。任何帮助都非常感谢!
【问题讨论】:
-
欢迎来到 SO!请使用
dput提供示例数据,以便我们重现您的问题。