2016-10-07 23 views
0

我嘗試使用下面的代碼來創建多個geom_smooth -lines:爲什麼在應用linetype = fl時R geom_smooth失敗(在mpg上)?

# 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.

回答

0

更少的數據值比自由度。

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

你真的無法順利在C單一的觀察,你需要排除或選擇另一種表示。

相關問題