2014-06-20 95 views
0

運行一個簡單繪圖,試圖根據一列的條件繪製兩列數據。基於列值繪製2D着色

Table <- read.csv("Del.csv",stringsAsFactors=FALSE) 
plot(DEL$PAST, DEL$ACTV, col=ifelse(is.na(DEL$PAST), 'blue', 'red')) 
dput(DEL, "foo") 

我看到

PAST = c(-3.68, NA, NA, 74.67, 147, 
233.47, 371.26, NA, NA, NA, 72.1, 72.1, NA, NA, NA, NA, NA, ... 

那麼,爲什麼情節出來都紅了?

+0

的'NA's沒有得到繪製。你會在哪裏放點? – jlhoward

+0

果然,我試圖將NA更改爲0,但失敗了。這確實是問題所在。 – Stone

回答

0

正如在評論中指出的那樣,NA不會陰謀。

set.seed(1) # for reproducible example 
DEL <- data.frame(PAST=sample(c(rep(NA,10),1:10),10, replace=T), 
        ACTV=sample(1:10,10)) 

par(mfrow=c(1,2)) 
# only get non-NA points 
with(DEL, plot(PAST,ACTV, main="NA does not plot")) 
# can set NA's to 0 - will plot on y-axis 
DEL$PAST <- ifelse(is.na(DEL$PAST),0,DEL$PAST) 
with(DEL, plot(PAST,ACTV, col=ifelse(PAST==0,"blue","red"), main="NAs set to 0"))