I believe that this plot should look like a smooth curve, but my plot is showing straight connected lines. Can someone point out my error?
Y <- c(0,2,-1,4)
t = c(1:4)
plot(t,Y)
c = smooth.spline(t,Y,lambda=1)
lines(t,c$y)
Thank you!
I believe that this plot should look like a smooth curve, but my plot is showing straight connected lines. Can someone point out my error?
Y <- c(0,2,-1,4)
t = c(1:4)
plot(t,Y)
c = smooth.spline(t,Y,lambda=1)
lines(t,c$y)
Thank you!
You can solve this issue by using the loess()
command.
Here you go:
Y <- c(0,2,-1,4)
t = c(1:4)
plot(t,Y)
lo <- loess(Y~t)
lines(predict(lo),col="blue", lwd=1.5)
Alternatively, you can use the qplot()
function, found in library(ggplot2)
library(ggplot2)
qplot(t,Y, geom='smooth', span =0.5)