在一个情节中着色不同的点

时间:2016-06-25 23:32:20

标签: r plot

我有

x1 <- runif(100,36.6,37.5)
x2 <- runif(100,37.5,38.5)
x3 <- runif(100,38.5,40)
all <- c(x1,x2,x3)
plot(all,col=c("red","yellow","blue"))

如何用红色绘制x1,用黄色绘制x2,用蓝色绘制x3

1 个答案:

答案 0 :(得分:3)

col参数与数据向量并行解释,因此您需要将每个值重复100次:

set.seed(101)    
x1 <- runif(100,36.6,37.5)
x2 <- runif(100,37.5,38.5)
x3 <- runif(100,38.5,40)
all <- c(x1,x2,x3)
plot(all,col=rep(c("red","yellow","blue"),each=100))

enter image description here