【发布时间】:2020-05-22 11:24:52
【问题描述】:
我正在尝试按照Karsten W 的建议使用smooth.spline 创建一条平滑线。我创建了一个简单的数据集,我在函数中调用它来绘制绘图。它已根据Parfait here 的建议进行汇总。
我正在尝试使用 smooth.spline 来创建最适合绘制的点,但要使其工作,我需要它只调用函数中的临时数据集,这是我无法做到的。
下面是一个独立的代码:
d1 <- c(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4)
d2 <- c(1:12)
d3 <- c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2)
df <- cbind(d1, d2, d3)
rm(d1, d2, d3)
average_plot <- function(a, b) {
for_plot <- aggregate(reformulate(a, b), df, mean)
smoothingSpline = smooth.spline(reformulate(a, b), spar=0.35)
plot(reformulate(a, b), for_plot)
lines(smoothingSpline)
}
average_plot("d1", "d3")
(我不得不承认我不太了解reformulate(a, b) 位,因为虽然它有效,但它与手册中显示的语法不同。)
任何帮助将不胜感激!
【问题讨论】:
标签: r plot curve-fitting