【问题标题】:Miscellaneous range of stat_smooth()stat_smooth() 的杂项范围
【发布时间】:2015-05-20 09:06:09
【问题描述】:

ggplot2-函数stat_smooth() 具有fullrange=TRUEFALSE 选项,用于决定是在数据范围内还是在图形范围内进行拟合。

有没有办法给stat_smooth() 一个杂项范围?例如。如果我的绘图在 (0,100) 中有 x,但在 (40,60) 中有拟合数据 x,则在 (30,70) 中绘制范围 x 的平滑拟合。

【问题讨论】:

    标签: r ggplot2 range data-fitting


    【解决方案1】:

    在您的stat_smooth 调用中使用xseq,如下所示:

    stat_smooth(xseq = seq(30,70, length=80))
    

    @ Hadley:为什么xseqn?geom_smooth 中未记录的绘图参数?源代码见这里:https://github.com/hadley/ggplot2/blob/master/R/stat-smooth.r

    示例:(改编自?geom_smooth

    ggplot(mtcars, aes(qsec, wt)) + 
      geom_point() + 
      xlim(c(10,30)) + 
      stat_smooth(method=lm, fullrange = TRUE, xseq = seq(11,25, length=80))
    

    结果:

    【讨论】:

    • 太棒了! length=80 的目的是什么?
    • 试试 xseq = c(11,25) 看看 CI 的差异。我猜 80 步预测点会产生合理的良好图形输出。 length = 80 是 hadley 的(所以 ggplot 的)标准。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    相关资源
    最近更新 更多