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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -