Reputation: 35
Hello Im trying to draw a plot on R and I have an error which is
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
and here is my code
lambda= 1.75
K1 = 1000
N = c(1)
for (t in 1:75) {
N = c(N,tail(N,1)*(1+lambda)*(1-log(tail(N,1))/log(K1)))
}
plot(t,N,
col="blue",type = "o",
ylim = c(0,max(N)),
xlab = "Time", ylab = "Popu" )
`
Upvotes: 0
Views: 765
Reputation: 173793
The variable t
takes a single value for each iteration of the loop. After the loop it has the single value 75
, whereas N
is a length 76 vector (the starting value of 1 plus one value for each iteration in the loop.
Therefore you could do:
plot(0:75, N,
col = "blue", type = "o",
ylim = c(0, max(N)),
xlab = "Time", ylab = "Popu")
Upvotes: 1