Q:

How to xyplot multiple lines in R

I would like to plot graphs with multiple lines in R like this:

2 lines
x axis is date
y axis is the log return

I have data in 3 vectors
print(class(TradeDate))
print(class(ArimaGarchCurve))
print(class(CompareCurve))
---------------------------------------------
[1] "factor"
[1] "numeric"
[1] "numeric"

I search and found that xyplot may be useful, but I don't know how to use it. I have tried.
pdf("Testing.pdf")
plotData <- data.frame(Date=TradeDate,
                       Arima=ArimaGarchCurve,
                       BuyHold=BuyHoldCurve)
print(xyplot(
    Arima ~ Date,
    data=plotData,
    superpose=T,
    col=c("darkred", "darkblue"),
    lwd=2,
    key=list(
        text=list(
            c("ARIMA+GARCH", "Buy & Hold")
        ),
        lines=list(
            lwd=2, col=c("darkred", "darkblue")
        )
    )
))
dev.off()

Here is the result:

Learn from here
Thank you very much.
dput(head(plotData,20))
structure(list(Date = structure(1:20, .Label = c("2001-12-03", 
"2001-12-04", "2001-12-05", "2001-12-06", "2001-12-07", "2001-12-10", 
"2001-12-11", "2001-12-12", "2001-12-13", "2001-12-14", "2001-12-17", 
"2001-12-18", "2001-12-19", "2001-12-20", "2001-12-21", "2001-12-24", 
"2001-12-25", "2001-12-26", "2001-12-27", "2001-12-28", "2001-12-31", 
"2002-01-01", "2002-01-02", "2002-01-03", "2002-01-04", "2002-01-07",
"2019-05-22", "2019-05-23"), class = "factor"), Arima = c(-0.0134052258713131, 
-0.00542641764174324, 0.0128513670753771, 0.0282761455973665, 
0.0179931884968989, 0.0281714817318116, 0.0435962602538011, 0.0462004298658309, 
0.0194592964361352, 0.0248069155406948, 0.032807001046888, 0.0381120657516546, 
0.0381120657516546, 0.030090589527961, -0.0146168717909267, -0.00630652663076437, 
-0.00630652663076437, -0.00630652663076437, 0.0100429785563596, 
0.0100429785563596), BuyHold = c(-0.0134052258713131, -0.00542641764174324, 
0.0128513670753771, 0.0282761455973665, 0.0384544388322794, 0.0281714817318116, 
0.0125050470584384, 0.0151092166704679, -0.0116319167592278, 
-0.0170082867113405, -0.0090082012051471, -0.00370313650038065, 
-0.00370313650038065, -0.0117246127240743, -0.056432074042962, 
-0.0481217288827996, -0.0481217288827996, -0.0481217288827996, 
-0.0317722236956757, -0.0317722236956757)), row.names = c(NA, 
20L), class = "data.frame")

A:

I think that this could help:
library(lattice)
xyplot(
  Arima + BuyHold ~ Date,                                   # here you can add log() to the two ts
  data=plotData,
  superpose=T,
  col=c("#cc0000", "#0073e6"),                              # similar colors
  lwd=2,
  key=list(
     text  = list(c("ARIMA+GARCH log", "Buy & Hold log")),
     lines = list( lwd=2, col=c("#cc0000", "#0073e6"))      # similar colors
  ), type=c("l","g")                                        # lines and grid
)

If you want to reduce the number of ticks on the x axis, you'd create your labels, and add them in this way (in this case, one year, you'd calculate your full time series parameters):
x.tick.number <- 1
at <- seq(1, nrow(d), length.out=x.tick.number)
labels <- round(seq(2001, 2001, length.out=x.tick.number))

In the plot:
xyplot(
  Arima + BuyHold ~ Date,                                   # here you can add log() to the two ts
  data=d,
  superpose=T,
  col=c("#cc0000", "#0073e6"),                              
  lwd=2,
  key=list(
    text  = list(c("ARIMA+GARCH log", "Buy & Hold log")),
    lines = list( lwd=2, col=c("#cc0000", "#0073e6"))      
  ), type=c("l","g"),
  scales = list(at=at, labels=labels, rot=90))

