简体   繁体   English

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

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

I have a graph that was smoothed using Scatter.Smooth function. 我有一个使用Scatter.Smooth函数进行平滑处理的图形。 I need to get the co-ordinates given the X-axis being the date. 我需要获得X轴为日期的坐标。

The smoothed curve is generated in Knime R Node. 平滑曲线在Knime R Node中生成。 I want the points so as to use it in a Line Plot node. 我想要这些点以便在“线图”节点中使用它。

Is there any other method to get the values from the generated graph to line plot in Knime? 还有其他方法可以将生成的图形中的值转换为Knime中的折线图吗?

Update 更新资料

I have added the R code that I used to generate the smooth curve in R node 我添加了用于在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

This is the function definition for R's scatter.smooth : 这是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()
}

It would seem that 看来

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

will contain what you need. 将包含您所需要的。

Using either scatter.smooth() or loess.smooth() to get points from a regression line is the wrong way to go about it. 使用scatter.smooth()或loess.smooth()从回归线上获取点是错误的处理方式。 Loess.smooth() is only providing enough points to plot a line it's not meant for predicting values. Loess.smooth()仅提供足够的点来绘制一条线,这并不意味着可以预测值。 You want to create an equation and then use that to predict on your original x points or a new set of points. 您想要创建一个方程式,然后使用该方程式来预测原始的x点或一组新的点。 There are tons of ways to do this loess.smooth (and thus scatter.smooth) both implement a local polynomial regression. loess.smooth(因此,scatter.smooth)有很多方法可以实现局部多项式回归。 To actually implement the regression and get an equation you might do something like this: 要实际实现回归并获得方程式,您可以执行以下操作:

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

If you'd like we can compare this to the results from loess.smooth() : 如果您愿意,我们可以将其与loess.smooth()的结果进行比较:

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

You'll notice the two methods produce slightly different results. 您会注意到两种方法产生的结果略有不同。 Neither is better or worse it is very dependent on the nature of your data and what your goals are. 无论是好是坏,它都很大程度上取决于数据的性质和目标是什么。 There a number of ways to evaluate regressions to try and assess both their accuracy and their validity. 有许多评估回归的方法,以尝试评估其准确性和有效性。

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

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