I just installed the latest version of R and installed the latest version of Rstudio and ran into an interesting problem.
It turned out that I can draw one graph
library(quantmod)
library(xts)
getSymbols('AAPL',src='yahoo')
AAPL <- tail(AAPL,200)
chart_Series(AAPL[sample(1:200,20)])
but I can't draw multiple graphs in sequence in a loop
for(i in 1:10){
chart_Series(AAPL[sample(1:200,20)])
}
there is no error, i just get a blank screen
There are no problems with a regular plot()
for(i in 1:10){
plot(rnorm(100))
}
session
> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
time zone: Asia/Damascus
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] quantmod_0.4.22 TTR_0.24.3 xts_0.13.1 zoo_1.8-12
loaded via a namespace (and not attached):
[1] compiler_4.3.0 tools_4.3.0 curl_5.0.0 grid_4.3.0
[5] jsonlite_1.8.4 lattice_0.21-8
You should use print
to return the plots like this:
library(quantmod)
library(xts)
getSymbols('AAPL',src='yahoo')
AAPL <- tail(AAPL,200)
for(i in 1:10){
print(chart_Series(AAPL[sample(1:200,20)]))
}