Getting x and y are different lengths in legend creations

I am trying to get my legend to work. It says that x and y are different lengths. However, my code works with everything but the legend. Here is where it stops working. Please help.

Here is the first part of my code:

CI <- predict(out, se.fit=TRUE)
W <- sqrt(2*qf(0.95,length(out$coefficients), out$df.residual))
Band <- cbind(CI$fit - W * CI$se.fit, CI$fit + W * CI$se.fit )

Here is the second part of my code:

points(sort(data$ACT), sort(Band[,1]), type="l", lty=1, col="springgreen4", lwd=3)
points(sort(data$ACT), sort(Band[,2]), type="l", lty=1, col="springgreen4", lwd=3)
legend("topleft", legend=c("Mean Line (-----)", "95% CB (red1)",
"95% Prediction (deepskyblue)", "WH (springgreen4)"), col=c(1,1))

It has been years since I have used base graphics but I think you need something like:

legend("topleft", legend=c("Mean Line (-----)", "95% CB",
"95% Prediction", "WH"), col=c("red1", "deepskyblue", "springgreen4"  ))

Otherwise can you supplyxus with more complete code and some sample data?

See
FAQ: How to do a minimal reproducible example ( reprex ) for beginners

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you! This really helped a lot!