【问题标题】:unable to plot regression line in R with ggplot2 update1无法使用 ggplot2 update1 在 R 中绘制回归线
【发布时间】:2020-10-07 18:40:10
【问题描述】:

这些是数据和代码的一部分,我想用 R 中的 ggplot2 绘制回归。 结果不理想,请问我犯了哪些错误?

     age purchase_freq
   <dbl> <chr>        
 1    81 30           
 2    61 89           
 3    54 67           
 4    33 43           
 5    55 35           
 6    58 25           
 7    31 71           
 8    20 10           
 9    77 18           
10    45 23           
# … with 900 more rows```

ggplot(test1, aes(x = age, y = purchase_freq)) +
   geom_point() +
   geom_smooth(method = "lm")

【问题讨论】:

  • 嗨詹姆斯。您能否帮助我们澄清一下结果是不受欢迎的?
  • 代码没有错误,可能是型号不对?
  • 对不起,我没有成功上传结果,我已经上传了@JasonPunyon

标签: r ggplot2 statistics regression


【解决方案1】:

purchase_freq 在您的数据框中是一个character,这意味着它的 y 值是离散的,这会使事情变得混乱。使用as.numeric 将其转换为数字,事情应该会变得更好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2017-02-05
    • 2018-05-27
    • 2013-06-05
    • 2018-09-04
    • 2017-06-19
    • 2015-01-15
    相关资源
    最近更新 更多