标签: 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?
x1
x2
x3
答案 0 :(得分:3)
col参数与数据向量并行解释,因此您需要将每个值重复100次:
col
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))