使用fda包,我创建了名为“弧线”的fd对象:
splinebasis = create.bspline.basis(rangeval = c(0,100),
nbasis = 23,
norder = 4)
curve = smooth.basis(x, y, splinebasis)$fd此时,我可以通过命令轻松地绘制fd对象:
plot(curve)

取得很好的结果。
我想做的是用ggplot2包绘制对象,但不幸的是,我不知道如何编码ggplot2 s.t。它用基和系数来返回连续曲线*。
发布于 2020-09-04 21:32:05
下面是一个简单的解决方案,使用来自predict包的fda。
library(fda)
set.seed(1)
x <- 0:100
y <- cumsum(rnorm(101))
splinebasis <- create.bspline.basis(rangeval = c(0,100),
nbasis = 23,
norder = 4)
curve <- smooth.basis(x, y, splinebasis)
# Plot using base graphic engine
plot(curve$fd)

# Plot using ggplot2
library(ggplot2)
xx <- seq(0,100,0.1)
df <- data.frame(x=xx, yhat = predict(curve, newdata=xx))
ggplot(data=df, aes(x=x, y=yhat)) +
geom_line() +
geom_hline(aes(yintercept=0), linetype=2) +
labs(x="time", y="value") +
theme_bw()

https://stackoverflow.com/questions/63745186
复制相似问题