I'm making some visualization using R Studio. I have a list of dataframes:
tickers_df <- read.csv('tickers.csv')
v_df <- split(tickers_df, tickers_df$pair_code)
Now I want to make a plot for each dataframe within v_df
in its own Viewer window. I'm doing:
for (pair_df in v_df) {
col_name <- names(pair_df)[4:9]
colors <- c('green', 'darkgreen', 'red', 'darkred', 'blue', 'darkblue')
df_layout <- data.frame(col_name, colors)
p <- plot_ly()
for (i in 1:nrow(df_layout)) {
col_name <- as.character(df_layout[i, 1])
p <-
add_trace(
p,
x = pair_df$step,
y = pair_df[, col_name],
name = col_name,
type = 'scatter',
mode = "lines",
line = list(color = df_layout[i, 2], width = 1)
)
p <- layout(p, title = pair_df$pair_code[[1]])
}
p
}
But this code doesn't work as expected - it shows no charts at all. How can I draw many plotly charts within a loop? And btw what is the meaning of last line with only p variable? Like in this example:
p <- plot_ly( x = df$time.1, y = df$total_profit, line = list(color = 'darkred'))
p #what is this standing for?