简体   繁体   中英

Multiple Lines in the Same Plot in R

Sorry if this is a repeat question but I couldn't figure it out from the other posts as I'm still learning R. I want to place the 3 stochastic lines on the plot but when I run my code it only plots the 3rd line on the original graph.

My code......

r=0.19
N=rep(0,50)
N[1]=13
K=130
for(t in 1:50){
N[t+1]= N[t] + N[t]*r*(1-(N[t]/K))}
plot(1:51, N, type="l", lwd=3, xlab="Time")

K=130
Ns=rep(0,50)
Ns[1]=13
for(t in 1:50){
r=rnorm(1, .19, 0.13)
Ns[t+1]= Ns[t] + Ns[t]*r*(1-(Ns[t]/K))}
plot(1:51, N, type="l", lwd=3, xlab="Time")
lines(1:51, Ns, lwd=3, col='blue')
lines(1:51, Ns, lwd=3, col='green')
lines(1:51, Ns, lwd=3, col='red')

You are not regenerating your random parameter, so all your lines use the same Ns . That is, they are drown on top of each other and you see only one of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM