r - How to apply loess.smoothing to both plot and then extract points? -
r - How to apply loess.smoothing to both plot and then extract points? -
i trying apply loess smoothing scatterplot (i.e. between 2 quantitative variables). plot loess smoothing occurs in scatterplot, , extract info points in scatterplot above smoothing.
for instance, if scatterplot:
qplot(mpg, cyl, data=mtcars)
and wanted superimpose smoother:
qplot(mpg, wt, data=mtcars) + with(mtcars, loess.smooth(mpg, wt))
this results in error: "don't know how add together o plot".
then, assuming superimposition work, extract cars above line.
[disclaimer: reply incomplete]
ggplot2
has function adding loess smoother: stat_smooth()
, e.g.
qplot(mpg, cyl, data=mtcars) + stat_smooth() # datasets n < 1000 default loess, hard-code: qplot(mpg, cyl, data=mtcars) + stat_smooth(method="loess")
the function help page states returns data.frame
predictions, can utilize extract points. this answer goes through it. unfortunately splits typically 80 points, might not align data, you'll have interpolation points above/below.
p.s. kind of 2 questions - i'd recommend splitting them in future.
r loess
Comments
Post a Comment