[英]plot 2D colored based on column value
Running a simple plot, trying to plot two columns of 2D data based on conditional of one column. 运行一个简单的图,尝试根据一列的条件绘制两列2D数据。
Table <- read.csv("Del.csv",stringsAsFactors=FALSE)
plot(DEL$PAST, DEL$ACTV, col=ifelse(is.na(DEL$PAST), 'blue', 'red'))
dput(DEL, "foo")
I see 我懂了
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, ...
So why plot comes out all red? 那么,为什么情节全变成红色了?
As pointed out in the comment, the NA's don't plot. 正如评论中指出的那样,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"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.