Consider the following code:
T=1
N=50
X=matrix(rnorm(N*4, mean = 0, sd = 1), 4, N)
t=seq(0,T,by=T/N)
t=head(t,-1)
ymax=max(X); ymin=min(X) #bounds for simulated prices
##Plot
led=c() # For ledgend purposes
ymax=max(X); ymin=min(X) #bounds for simulated prices
plot(t,X[1,], t='l', ylim=c(ymin, ymax), col=1, ylab="Price P(t)", xlab="time t")
led=c(led, paste("GBM", 1))
for(i in 2:4){
lines(t, X[i,], t='l', ylim=c(ymin, ymax), col=i)
led=c(led, paste("GBM", i))
}
legend(0, 0, legend=led, lty=1:4, cex=0.8)
As you can see the legend is not observed and if they are observed they are of another colour of that of the lines.
How can I make the legend represent the colour without using the ggplot2? And how to use it with my own created legend?



