[R] Ploting lines with different lenght

Pedro páramo percent||101 @end|ng |rom gm@||@com
Tue Jul 21 10:25:47 CEST 2020


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]]



More information about the R-help mailing list