r-使用ls()模式创建子地块的地块列表



我正在运行一个循环,该循环将绘图分配给变量。然后,代码使用ls((模式函数提取变量名

while (i > 0) {
assign(paste("fig", i, sep = ""), plot_ly(tot, y = ~gene, color = ~bx, type = "box", boxpoints = "all") %>% layout(annotations = list(x = 0 , y = 1, xanchor = "left",yanchor = "top",yshift = 20,showarrow = FALSE,font = list(size = 20), text = paste("Data", colnames(total)[i+1]))))
i = i-1
if (i == 0){

然后,代码使用ls((模式函数提取变量名,并尝试将它们作为列表传递给子地块。

...
l <- as.list(ls(pattern = "fig"))
l <- do.call(paste, c(l,sep=", "))
fig <- subplot(l,margin = 0.06,nrows=2) %>% layout(showlegend = FALSE)
fig
}
}'

这就是我遇到一些错误的地方。

Error in [[: subscript out of bounds

尝试以下操作:

library(plotly)
l <- mget(ls(pattern = "fig"))
fig <- subplot(l,margin = 0.06,nrows=2) %>% layout(showlegend = FALSE)

最新更新