ggplot2中不太平滑的线,geom_smooth的替代品? [英] Less smoothed line in ggplot2, alternatives to geom_smooth?

查看:198
本文介绍了ggplot2中不太平滑的线,geom_smooth的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下数据:

 > str(属性)
'data.frame':431 obs。 2个变量:
$ pos:int 1 2 3 4 5 6 7 8 9 10 ...
$ att:num 0.652 0.733 0.815 1.079 0.885 ... * [介于0和3之间]



  ggplot(attribute,aes(x = pos,y = att))+ geom_line()+ geom_smooth()

我做了:



我想渐进地平滑黑色曲线,而不是geom_smooth默认值。我试过 n level 选项,但是没有按照我的意愿去做。这将是逐步增加平滑的最佳方法? (例如,一个中的平均值为2,然后在一个中尝试3,依此类推)。我想这很容易实现,但不使用 geom_smooth ,但我不知道要搜索/查找什么。谢谢。

解决方案

记录在 stat_smooth 中。默认的平滑器是 loess ,并且附加的参数被传递给它,正如对 ... 论据。所以你想要什么是 span

  ggplot(mtcars,aes( x = wt,y = mpg))+ 
geom_point()+
geom_smooth(span = 0.4)

此外, loess 接受度数参数,以更好地控制平滑量。 / p>

Using the following data:

> 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]

and:

ggplot(attribute, aes(x=pos, y=att)) + geom_line() + geom_smooth()

I did:

I would like to progressively smooth the black curve, not "as much as" geom_smooth default did. I've tried n, level options, but didn't do what I want. Which would be the best way to increase smoothing progressively? (e.g. average 2 values in one, then try 3 in one, and so on). I guess it's something really easy or achievable without using geom_smooth, but I don't know what to search/look for. Thanks.

解决方案

This is documented in stat_smooth. The default smoother is loess, and additional arguments are passed on to it, as specified for the description of the ... argument. So what you want is span:

ggplot(mtcars,aes(x = wt,y = mpg)) + 
  geom_point() + 
  geom_smooth(span = 0.4)

Additionally, loess accepts a degree argument for more control over the amount of smoothing.

这篇关于ggplot2中不太平滑的线,geom_smooth的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆