Ploting lines with different lenght

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Ploting lines with different lenght

Pedro páramo
Plotting lines with different "lenght"

I am trying trying to plot a chart thar always have values from 01/01 of
the beginning of the year till 31/12 of the end of the year.

The thing is sometimes I will have NA or not values in one time series but
not in the others. In the next code you can see two variables b (with a
length of 138 of the current year) and b2019 (of the previous year) but I
want to plot both b and b2019 in one chart with the X-axis from 01/01 to
31/12 without specifying the year.

Can someone guide me with this:

Code:

library(PerformanceAnalytics)
library(quantmod)
library(tidyverse)
library(tidyquant)
loadSymbols("TSLA")
a<-dailyReturn(TSLA,subset='2020')
a2019<-dailyReturn(TSLA,subset='2019')
b<-cumsum(a)*100
b2019<-cumsum(a2019)*100

plot(b, type = "l", lty = 1)
lines(b2019, type = "l", lty = 4)

Many thanks in advance

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.