如何根据两个滤镜的条件在散点图上着色点?

时间:2015-02-10 20:11:13

标签: r plot

我有一个散点图,我想对点进行着色,以便满足这两个条件的所有点都是红色的。条件是abs(x) > .15abs(y)>1.4

colour <- ifelse(abs(x)>.15, "red", "black")
colour <- ifelse(abs(y)>1.4, "red", "black")
# colour <- ifelse((abs(y)>1.4&&abs(x)>.15), "red", "black") #all black
plot(y, x, main="scatter - meth vs exp - diff", xlab="delta beta (.15)", ylab="log2(exp)", col=colour)
abline(h=c(-1.4, 1.4), v=c(-.15, .15), col="gray", lty=3)

我在这里缺少什么?感谢任何建议。

1 个答案:

答案 0 :(得分:1)

这是否会产生预期效果?

x <- rnorm(10)
y <- rnorm(10)
colour <- ifelse(abs(x)>.15 & abs(y)>1.4, "red", "black")
# colour <- ifelse((abs(y)>1.4&&abs(x)>.15), "red", "black") #all black
plot(y, x, main="scatter - meth vs exp - diff", xlab="delta beta (.15)", ylab="log2(exp)", col=colour)
abline(h=c(-1.4, 1.4), v=c(-.15, .15), col="gray", lty=3)

使用&组合这两个条件。