I have a dataframe in R, I am plotting line charts within using the code below. I want to create function to do the same thing that takes some parameters.
plot(df[,1], df[,2], xlab="Date", ylab="Asset Value", type='l', col=1)
# now add the others
for(j in 2:ncol(Returns)) {
lines(date, Returns[,j], col=j)
}
legend('topleft', names(Returns), col=1:3, lty=rep(1,3))
I am able to plot the chart with it. But, now I want to plot the same chart with a function in R.
The function should take 3 arguments: df[,1] gives the dates, df[,x] and x which is a number.