ggplot2 中平滑度较低的线条,geom_smooth 的替代方案?
Less smoothed line in ggplot2, alternatives to geom_smooth?
使用以下数据:
> str(attribute)
'data.frame': 431 obs. of 2 variables:
$ pos: int 1 2 3 4 5 6 7 8 9 10 ...
$ att: num 0.652 0.733 0.815 1.079 0.885 ... *[between 0 and 3]
和:
ggplot(attribute, aes(x=pos, y=att)) + geom_line() + geom_smooth()
我做了:
我想逐渐平滑黑色曲线,而不是 "as much as" geom_smooth 默认值。我尝试了 n
、level
选项,但没有按照我的意愿进行。哪种方式是逐步增加平滑度的最佳方式? (例如,平均 2 个值,然后尝试 3 个值,依此类推)。我想这很容易或不使用 geom_smooth
就可以实现,但我不知道 search/look 有什么用。谢谢。
stat_smooth
中对此进行了记录。默认的平滑器是 loess
,并且附加参数被传递给它,如 ...
参数的描述所指定的那样。所以你想要的是 span
:
ggplot(mtcars,aes(x = wt,y = mpg)) +
geom_point() +
geom_smooth(span = 0.4)
此外,loess
接受 degree
参数以更好地控制平滑量。
使用以下数据:
> str(attribute)
'data.frame': 431 obs. of 2 variables:
$ pos: int 1 2 3 4 5 6 7 8 9 10 ...
$ att: num 0.652 0.733 0.815 1.079 0.885 ... *[between 0 and 3]
和:
ggplot(attribute, aes(x=pos, y=att)) + geom_line() + geom_smooth()
我做了:
我想逐渐平滑黑色曲线,而不是 "as much as" geom_smooth 默认值。我尝试了 n
、level
选项,但没有按照我的意愿进行。哪种方式是逐步增加平滑度的最佳方式? (例如,平均 2 个值,然后尝试 3 个值,依此类推)。我想这很容易或不使用 geom_smooth
就可以实现,但我不知道 search/look 有什么用。谢谢。
stat_smooth
中对此进行了记录。默认的平滑器是 loess
,并且附加参数被传递给它,如 ...
参数的描述所指定的那样。所以你想要的是 span
:
ggplot(mtcars,aes(x = wt,y = mpg)) +
geom_point() +
geom_smooth(span = 0.4)
此外,loess
接受 degree
参数以更好地控制平滑量。