为什么 R geom_smooth 在应用 linetype=fl 时失败(在 mpg 上)?

Why does R geom_smooth fail (on mpg) when applying linetype=fl?

我正在尝试使用以下代码创建多个 geom_smooth 行:

# Install necessary packages
install.packages("tidyverse")
library(tidyverse)

# Create the plot
ggplot(data = mpg) +
  geom_smooth(mapping = aes(x = displ, y = hwy, linetype = fl, colour = fl, fill = fl))

但是,每当我将它映射到 fl 时,它都会失败并显示以下错误消息:

Warning messages:
1: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  span too small.   fewer data values than degrees of freedom.
2: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  at  1.877
3: … : radius  0.000529
4: … : all data on boundary of neighborhood. make span bigger
5: … : pseudoinverse used at 1.877
6: … : neighborhood radius 0.023
7: … : reciprocal condition number  1
8: … : There are other near singularities as well. 21.372
9: … : zero-width neighborhood. make span bigger
10: Computation failed in `stat_smooth()`:
NA/NaN/Inf in foreign function call (arg 5) 

奇怪的是,即使将其映射到一些惊人的东西时,它也能很好地工作,例如 class(看起来像迪斯尼给它涂上了颜色)。人们不应该能够将其映射到燃料类型,这似乎很奇怪,因为这种数据似乎非常适合此类研究。这是一个错误,还是我完全遗漏了什么?

我是 运行 RStudio 0.99.902 并且是 R 的新手。

fewer data values than degrees of freedom.

> table(mpg$fl)
  c   d   e   p   r   
  1   5   8  52 168 

你不能真正平滑 c 中的单个观察,你需要排除它或选择其他表示。