0

I came across a problem with creating a list of plots. I have created garch predictions and I have those values in list:

for(i in 1:length(Tickery))
{
name <- paste(Tickery[i])
log_ret <- diff(log(CP_list[[i]]))
log_ret_list[[name]] <- log_ret
gspec.ru <- ugarchspec(mean.model=list(
armaOrder=c(0,0)),
distribution="std")
gfit.ru <- ugarchfit(gspec.ru, log_ret)
GARCH_list[[name]] <- gfit.ru@fit$sigma
}

So values for different stocks are in GARCH_list[[i]]. I have tried to make a list of plots of those volatilities:

for(i in 1:length(Tickery))
{
a <- ggplot(NULL, aes(x = 1:length(GARCH_list[[i]]), y = GARCH_list[[i]])) + 
     geom_line() + 
     labs(x = "Obserwacje", y = "Zmienność", title = paste(Tickery[i]))
pl[[i]] <- a
}

Unfortunately in every item of list (pl[[i]]) I have the same plot, the last one. What's wrong in my code?

ltrd
  • 326
  • 1
  • 8
  • I recently answered a [similar question](https://stackoverflow.com/questions/46071417/ggplot2-overwrites-plots-when-saving-in-a-list/46075105) on this. See if the explanation makes sense to you? – Z.Lin Sep 15 '17 at 08:56
  • ` g_x <- length(GARCH_list[[i]]) g_y <- GARCH_list[[i]] a <- ggplot(NULL, aes(x = 1:g_x, y = g_y)) + geom_line() a <- a + labs(x = "Obserwacje", y = "Zmienność", title = paste(Tickery[i])) pl[[i]] <- a` – ltrd Sep 15 '17 at 09:11
  • Try `pl[[i]] <- ggplotGrob(a)` instead? – Z.Lin Sep 15 '17 at 10:00

0 Answers0