根据列值绘制2D彩色图

时间:2014-06-20 16:12:51

标签: r

运行简单的绘图,尝试根据一列的条件绘制两列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, ...

那么为什么情节出现全红?

1 个答案:

答案 0 :(得分: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"))