R-在列表中存储plotly对象
我试图在for循环中生成不同的绘图,并将它们保存到列表中。问题是plotly的数据不是静态的,在每个循环中,所有的绘图都在变化。 这是我的密码:R-在列表中存储plotly对象,r,plotly,R,Plotly,我试图在for循环中生成不同的绘图,并将它们保存到列表中。问题是plotly的数据不是静态的,在每个循环中,所有的绘图都在变化。 这是我的密码: library(plotly) data("iris") names = names(iris)[-5] plotList <- list() for (i in 1:length(names)) { for (j in 1:length(names)) { name = paste("plot", i, j, sep = "_")
library(plotly)
data("iris")
names = names(iris)[-5]
plotList <- list()
for (i in 1:length(names)) {
for (j in 1:length(names)) {
name = paste("plot", i, j, sep = "_")
p <- (plot_ly(data = iris, x = ~get(names[i]), y = ~get(names[j]),
type = "scatter", mode = "markers") %>%
layout(
title = paste(names[i], names[j], sep = " vs "),
xaxis = list(title = names[i]),
yaxis = list(title = names[j])))
plotList[[name]] <- p
}
}
plotList$plot_4_3
plotList$plot_4_4
library(plotly)
数据(“iris”)
姓名=姓名(虹膜)[-5]
plotListAddplotly\u build
:
library(plotly)
data("iris")
names = names(iris)[-5]
plotList <- list()
for (i in 1:length(names)) {
for (j in 1:length(names)) {
name = paste("plot", i, j, sep = "_")
plotList[[name]] <- plotly_build(plot_ly(data = iris, x = ~get(names[i]), y = ~get(names[j]),
type = "scatter", mode = "markers") %>%
layout(
title = paste(names[i], names[j], sep = " vs "),
xaxis = list(title = names[i]),
yaxis = list(title = names[j])))
}
}
plotList$plot_4_3
plotList$plot_4_4
library(plotly)
数据(“iris”)
姓名=姓名(虹膜)[-5]
绘图仪
library(plotly)
data("iris")
names = names(iris)[-5]
plotList <- list()
for (i in 1:length(names)) {
for (j in 1:length(names)) {
name = paste("plot", i, j, sep = "_")
plotList[[name]] <- plotly_build(plot_ly(data = iris, x = ~get(names[i]), y = ~get(names[j]),
type = "scatter", mode = "markers") %>%
layout(
title = paste(names[i], names[j], sep = " vs "),
xaxis = list(title = names[i]),
yaxis = list(title = names[j])))
}
}
plotList$plot_4_3
plotList$plot_4_4