[英]changing specific points in scatterplot with matrix
I want to pass a matrix with x and y values that correspond to points in a scatterplot. 我想传递一个x和y值对应于散点图中的点的矩阵。 I then want to change the color of these specific points in the scatter plot. 然后,我想更改散点图中这些特定点的颜色。 I have looked online, but no obvious approach has stood out. 我在网上看过,但是没有明显的方法脱颖而出。
Here is the original data 这是原始数据
set.seed(100)
rand.x <-rnorm(1000,0,1)
rand.y <-rnorm(1000,0,1)
plot(rand.x, rand.y, col='black', cex=.5, pch=20)
This is a test matrix I want to use to modify the colors of the plot from black to red. 这是我要用来将图的颜色从黑色更改为红色的测试矩阵。
color_changer = cbind(rand.x[1:4], rand.y[1:4])
[,1] [,2]
[1,] -0.50219235 1.0976501
[2,] 0.13153117 1.1810365
[3,] -0.07891709 0.5875107
[4,] 0.88678481 1.0761726
set.seed(100)
rand.x <-rnorm(1000,0,1)
rand.y <-rnorm(1000,0,1)
plot(rand.x, rand.y, col='black', cex=.5, pch=20)
color_changer = cbind(rand.x[1:4], rand.y[1:4])
# To add more points to the same plot use points()
points(color_changer, col='red', cex=.5, pch=20)
I think you could use the function lines
for that, even though it is designed for lines 我认为您可以为此使用功能lines
,即使它是为行而设计的
lines(color_changer[,1],color_changer[,2], col = "red", pch = 20, type = "p")
In this examples the type = "p"
enables you to have points and the pch = 20
also dots that can stick out among the other ones. 在此示例中, type = "p"
使您可以拥有点,而pch = 20
以及其他点之间可以突出的点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.