I am trying to plot multiple graphs on the same page. It works fine when I write the code one by one like this:
old.par <- par(mfrow = c(3,4))
plot(na.omit(AUS.Yield), xlab = "Date", ylab = "log_return", main = "AUS.Yield")
plot(na.omit(BRA.Yield), xlab = "Date", ylab = "log_return", main = "BRA.Yield")
plot(na.omit(CAN.Yield), xlab = "Date", ylab = "log_return", main = "CAN.Yield")
plot(na.omit(CHI.Yield), xlab = "Date", ylab = "log_return", main = "CHI.Yield")
plot(na.omit(GER.Yield), xlab = "Date", ylab = "log_return", main = "GER.Yield")
plot(na.omit(JAP.Yield), xlab = "Date", ylab = "log_return", main = "JAP.Yield")
plot(na.omit(SOA.Yield), xlab = "Date", ylab = "log_return", main = "SOA.Yield")
plot(na.omit(SWI.Yield), xlab = "Date", ylab = "log_return", main = "SWI.Yield")
plot(na.omit(UK.Yield), xlab = "Date", ylab = "log_return", main = "UK.Yield")
plot(na.omit(US.Yield), xlab = "Date", ylab = "log_return", main = "US.Yield")
But it does not work when I try to use a for loop e.g.:
## names(log_return[2:11]) will give me all those AUS.Yield, BRA.Yield etc as they are the column names of dataframe log_return
for (i in names(log_return[2:11]){
plot(na.omit(i), xlab = "Date", ylab = "log_return", main = "i")
}
Also, I have generated 10 time series by using:
for (i in 2:length(log_return)){
assign(names(log_return[i]),xts(log_return[i],log_return$Date))
}
so I got 10 time series that names: AUS.Yield, BRA.Yield.... etc.
Just wondering where went wrong.... Here is the error message:
Error in plot.window(...) : need finite 'ylim' values
I am thinking maybe I got so many NAs in my dataframe? But I have used the na.omit already.
Here is a small section of the datafram log_retrun;
Date AUS.Yield BRA.Yield CAN.Yield CHI.Yield GER.Yield JAP.Yield
1 2008-01-01 NA NA NA NA NA NA
2 2008-01-02 NA NA NA NA NA NA
3 2008-01-03 -0.033047602 -0.01239795 0.003828977 -0.017857617 -0.031966192 NA
4 2008-01-04 -0.003922215 0.00198792 -0.008443187 0.006734032 -0.006984895 NA
5 2008-01-05 NA NA NA NA NA NA
6 2008-01-06 NA NA NA NA NA NA
The JAP.Yield may look all NAs but there are values after a several lines.
Thank you in advance for any help and suggestion!! T_T