繁体   English   中英

如何在R中将图形转换为数据点

[英]How to convert graph to data points in R

我有一个使用Scatter.Smooth函数进行平滑处理的图形。 我需要获得X轴为日期的坐标。

平滑曲线在Knime R Node中生成。 我想要这些点以便在“线图”节点中使用它。

还有其他方法可以将生成的图形中的值转换为Knime中的折线图吗?

更新资料

我添加了用于在R节点中生成平滑曲线的R代码

 plot(x,y)
 scatter.smooth(x,y)

 //x<- Date
 //y <- Frequency
 //Basically the values are from the Data file in another node. For simplicity I have mentioned it as comments

这是R的scatter.smooth的函数定义:

function (x, y = NULL, span = 2/3, degree = 1, family = c("symmetric", 
    "gaussian"), xlab = NULL, ylab = NULL, ylim = range(y, pred$y, 
    na.rm = TRUE), evaluation = 50, ..., lpars = list()) 
{
    xlabel <- if (!missing(x)) 
        deparse(substitute(x))
    ylabel <- if (!missing(y)) 
        deparse(substitute(y))
    xy <- xy.coords(x, y, xlabel, ylabel)
    x <- xy$x
    y <- xy$y
    xlab <- if (is.null(xlab)) 
        xy$xlab
    else xlab
    ylab <- if (is.null(ylab)) 
        xy$ylab
    else ylab
    pred <- loess.smooth(x, y, span, degree, family, evaluation)
    plot(x, y, ylim = ylim, xlab = xlab, ylab = ylab, ...)
    do.call(lines, c(list(pred), lpars))
    invisible()
}

看来

pred <- loess.smooth(x, y, span, degree, family, evaluation)

将包含您所需要的。

使用scatter.smooth()或loess.smooth()从回归线上获取点是错误的处理方式。 Loess.smooth()仅提供足够的点来绘制一条线,这并不意味着可以预测值。 您想要创建一个方程式,然后使用该方程式来预测原始的x点或一组新的点。 loess.smooth(因此,scatter.smooth)有很多方法可以实现局部多项式回归。 要实际实现回归并获得方程式,您可以执行以下操作:

library(locfit)
x <- rnorm(50, 20, 2)
y <- rnorm(50, x, 1)
myLoc <- locfit(x~y)
predPoints <- predict(myLoc, x)

如果您愿意,我们可以将其与loess.smooth()的结果进行比较:

mySmooth <- loess.smooth(x,y)
plot(x,y)
points(x, predPoints, col = 'red')
points(mySmooth$x, mySmooth$y, col = 'blue')

您会注意到两种方法产生的结果略有不同。 无论是好是坏,它都很大程度上取决于数据的性质和目标是什么。 有许多评估回归的方法,以尝试评估其准确性和有效性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM