Question

I am using base R graphics to make a scatterplot with thousands of data points. One point out of these has the highest 'y' value. I want to fill this point to make it look different. In the past I have accomplished this with one of the following. Of course then the number of points were very few and thus I was able to manage it easily. Now I have ~3000 points. Any ideas?

col=c{'black','black','black','red','black','black'}
pch=c(16,16,16,17,16,16)
Was it helpful?

Solution

Option 1: Identify the max and make your color vector

set.seed(47)
n <- 1e4
xx <- runif(n)
yy <- rexp(n)
colors <- rep("black", n)
colors[which.max(yy)] <- "red"
plot(xx, yy, col = colors, pch = 16)

Option 2: Plot the max separately. This is probably easier, especially if you want to adjust more characteristics than just color.

plot(xx, yy, pch = 16)
points(xx[which.max(yy)], yy[which.max(yy)], col = "red", pch = 17, cex = 2)

OTHER TIPS

I think it may be a bit faster to just do:

plot(xx, yy, col=(yy==max(yy)), pch=19)

This will create a vector of TRUE and FALSE values which will be coerced into 1s and 0s, so you may have to attach a +1 to that statement to avoid using white:

plot(xx, yy, col=(yy==max(yy))+1, pch=19)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top