0

我有两个向量

 A=rnorm(500)
 B=rnorm(500)

并想创建一个散点图并使用

   Plot(A,B,cex=0.5,col="grey") ### this creates the base scatterplot

现在,我还有两个条件,其中我有三个向量,它们是原始向量的子集:

 C<-subset[A,select=c(1:10,20:30,60:75,90,100) ### to be coloured in blue
 D<-subset[A,select=c(25:60)] ### to be coloured in blue
 E<-subset[B,select=c(100:150,120:125)] ### to be colured in red.

我应该如何修改散点图以仅从原始灰色更改这些向量 C、D、E 的颜色?这个概念与此类似:

XY 散点图

4

1 回答 1

3

这就是我解释你的问题的方式:

“用不同颜色在问题中绘制由索引C,指示的点的子集”。DE

A <- rnorm(500)
B <- rnorm(500)

## Set the indices, as written in question
Ci <- c(1:10,20:30,60:75,90,100) ### to be coloured in blue
Di <- c(25:60)                   ### to be coloured in blue
Ei <- c(100:150,120:125)         ### to be coloured in red.

## Plot the original scatterplot, then plot over the points of interest with colour
## Use the "points" function from base graphics to plot points on existing plot
## Grab the relevant points from vectors A and B by accessing them at indices 
## Ci, Di, Ei using `[]`
plot(A, B, cex=0.5, col="grey")
points(A[Ci], B[Ci], cex=0.5, col="blue")
points(A[Di], B[Di], cex=0.5, col="blue")
points(A[Ei], B[Ei], cex=0.5, col="red")
于 2013-10-04T19:09:16.373 回答