2017-09-04 32 views
0

每當我嘗試並在各個因素間繪圖時,我總是得到錯誤。格點圖錯誤:需要有限xlim值調用

這裏是我的數據看起來像:

str(dataWithNoNa) 

## 'data.frame': 17568 obs. of 4 variables: 
## $ steps : num 1.717 0.3396 0.1321 0.1509 0.0755 ... 
## $ date : Factor w/ 61 levels "2012-10-01","2012-10-02",..: 1 1 1 1 1 1 1 1 1 1 ... 
## $ interval: int 0 5 10 15 20 25 30 35 40 45 ... 
## $ dayType : Factor w/ 2 levels "Weekday","Weekend": 1 1 1 1 1 1 1 1 1 1 ... 

我想用用工作日/週末的一個因素點陣繪圖系統繪製。

這裏是我的嘗試:

plot(dataWithNoNa$steps~ dataWithNoNa$interval | dataWithNoNa$dayType, type="l") 

Error in plot.window(...) : need finite 'xlim' values 

我甚檢查,以確保我的數據沒有來港:

sum(is.na(dataWithNoNa$interval)) 
## [1] 0 
sum(is.na(dataWithNoNa$steps)) 
## [1] 0 

我在做什麼錯?

+2

請使用dput(),不STR(),以輸出所述結構,以便該數據可用於可重現的示例。 – www

+0

您的繪圖公式看起來像'lattice'軟件包的語法。 – lmo

+0

不是名爲'xyplot'的'lattice'繪圖函數嗎?看來你正在使用一個非法公式的基礎圖形。 –

回答

1

嘗試這種情況:

library(lattice) 

xyplot(steps ~ interval | factor(dayType), data=df) 

輸出:

enter image description here

樣本數據:

df <- data.frame(
    steps=c(1.717,0.3396,0.1321,0.1509,0.0755), 
    interval=c(0,5,10,15,20), 
    dayType=c(1,1,1,2,2) 
) 
+0

工作。我需要加載庫 - 多麼尷尬。謝謝 –

+0

它發生了,沒問題。請將此答案標記爲解決方案,以便將來人們更容易回答。 – www

相關問題