R stat_smooth所有数据点

10

Plot vectors of different length with ggplot2得到了我的线条图。

ggplot(plotData, aes(x, y, label=label, group=label)) + geom_line() + stat_smooth()

但是这只能使每行都变得平滑。我该如何平滑所有数据点?


2
我发现您在过去的24小时内问了很多类似的问题。也许您可以从更多地花时间学习R教程中受益,例如:https://sites.google.com/site/r4statistics/example-programs/graphics-ggplot2和http://egret.psychol.cam.ac.uk/statistics/R/graphs2.html。 - Carl Witthoft
1个回答

16
ggplot(plotData, aes(x, y, label=label, group=label)) + 
    geom_line() +
    geom_smooth(aes(group = 1))

应该这样做。这里的想法是提供一个新的组美学,以便拟合平滑器基于所有数据,而不是基于 group=label 美学。

根据 @Andrie 的答案 的示例,我建议进行修改:

ggplot(plotData, aes(x, y, label=label, group=label)) + 
    geom_text() + 
    geom_smooth(aes(group = 1))

这将产生以下结果:

在此输入图像描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接