how to change the smoothing index of loess regression in ggplot2

1,117 views
Skip to first unread message

王丽

unread,
Nov 4, 2015, 6:51:55 PM11/4/15
to ggplot2

In the R default plotting, users can change the f index to vary the smoothing level of loess regression (high f means high smooth). I did the loess regression with ggplot2 stat_smooth with the following command: ggplot(data=combine, aes(x=pos/1000000, y=weightedFst, color=group, group=group)) + geom_smooth(method="loess", size=1, formula = y ~ x) + scale_x_continuous(limits=c(0, 302), breaks=c(50, 250)) + xlab("physical position (Mb)") + ylab("Fst") + ggtitle("loess regression of Fst in 10kb non-overlapping windows") + theme_bw()

How can I change the smoothing level of loess regression in ggplot2? I searched around but could not find the answers. Could anyone help here?


Roman Luštrik

unread,
Nov 5, 2015, 2:57:59 AM11/5/15
to 王丽, ggplot2
​Hi,

`loess`'s "smoothness" is controlled by span. Is that what you mean? Here's a short example.

ggplot(data=mtcars, aes(x = mpg, y = drat)) + 
  geom_smooth(method="loess", size=1, formula = y ~ x, span = 2)  + 
  theme_bw()

Cheers,
Roman​

On Wed, Nov 4, 2015 at 12:18 PM, 王丽 <lilep...@gmail.com> wrote:

In the R default plotting, users can change the f index to vary the smoothing level of loess regression (high f means high smooth). I did the loess regression with ggplot2 stat_smooth with the following command: ggplot(data=combine, aes(x=pos/1000000, y=weightedFst, color=group, group=group)) + geom_smooth(method="loess", size=1, formula = y ~ x) + scale_x_continuous(limits=c(0, 302), breaks=c(50, 250)) + xlab("physical position (Mb)") + ylab("Fst") + ggtitle("loess regression of Fst in 10kb non-overlapping windows") + theme_bw()

How can I change the smoothing level of loess regression in ggplot2? I searched around but could not find the answers. Could anyone help here?


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.

王丽

unread,
Nov 5, 2015, 5:56:03 AM11/5/15
to Roman Luštrik, ggplot2
Thank you, Roman! Yes, I just want to know the parameter to control the smoothness of loess regression. However, it seems the "span" is somehow different from "f" in base graph. the range of "f" is from 0 to 1. Higher f means smoother. Lower f means higher local resolution. What about "span" in ggplot2? I cannot find any information regarding this.

Best
Li

Roman Luštrik

unread,
Nov 5, 2015, 6:07:48 AM11/5/15
to 王丽, ggplot2
AFAIK, method = "loess" uses stats::loess. Are you using any other packages that comes with a loess function?

Cheers,
Roman

王丽

unread,
Nov 5, 2015, 7:46:51 AM11/5/15
to Roman Luštrik, ggplot2
No, no other packages are used. Just want to ask if there is a maximum/minimum span value.

Cheers
Li

Roman Luštrik

unread,
Nov 5, 2015, 8:06:47 AM11/5/15
to 王丽, ggplot2
Unfortunately I don't know much more than what's specified in the docs:

For α < 1, the neighbourhood includes proportion α of the points, and these have tricubic weighting (proportional to (1 - (dist/maxdist)^3)^3). For α > 1, all points are used, with the ‘maximum distance’ assumed to be α^(1/p) times the actual maximum distance for p explanatory variables.

Cheers,
Roman
Reply all
Reply to author
Forward
0 new messages