geom_smooth不绘制最佳拟合线

时间:2018-05-13 18:55:19

标签: r ggplot2

我希望这个问题不重复。在发布之前,我试图根据网站的要求找到答案,但由于我是如此新,所以帮助论坛对我来说太陌生了。

按照Wickham的 R进行数据可视化,我很容易将geom_point用于集成数据集,mpg:

smooth fit for integrated data set

简单的参考代码:

ggplot(data = mpg)+
    geom_smooth(mapping = aes(x=displ, y=hwy))+
    geom_point(mapping = aes(x=displ, y=hwy))

对于这个很酷的情节感兴趣,我尝试对一些个人研究数据做同样的事情,这些数据描述了五个时间点(A,b,c,d,e而不是数值数据)的干扰素-β产生。

我使用了相同的代码,基本上是:

ggplot(data = ifnonly)+
    geom_smooth(mapping = aes(x=HOURS, y=IFNB))+
    geom_point(mapping = aes(x=HOURS, y=IFNB))

IFNb expression at five timepoints

不幸的是,该行不显示。实际上,在添加geom_point函数之前,没有任何内容显示。我在这里错过了什么?是否需要更复杂的代码,或者我是否可以应用于此函数和ggplot的未来使用?

1 个答案:

答案 0 :(得分:0)

我认为您应该通过以下一行代码获得所需的输出

          library(ggplot2)
          ggplot(mtcars, aes(disp,mpg))+geom_smooth() # one line code where I have mentioned data is mtcars , and disp as x axis and mpg as y axis you could get following output  
    # please check this link for output 

o/p without geom_point

         library(ggplot2)
          ggplot(mtcars, aes(disp,mpg))+geom_smooth()+geom_point()

o/p with geom_point

相关问题