I was wondering if R enables to print (or highlight) only the points of the input data set that are Pareto-optimal.
For example, in the below 2D plot you can observe a set of 50 points. I would like to be able to print the Pareto-optimal points with different colours. In this example, consider that the two two dimensions are to be minimised.
http://i42.tinypic.com/jso7ma.png
Any tips?
Edit:
According to a comment, I achieved the desired result with the following code:
n <- 40
d <- data.frame(
x = rnorm(n),
y = rnorm(n)
)
# We want the "extreme" points in the following plot
par(mar=c(1,1,1,1))
plot(d, axes=FALSE, xlab="", ylab="")
for(i in 1:n) {
polygon( c(-10,d$x[i],d$x[i],-10), c(-10,-10,d$y[i],d$y[i]),
col=rgb(.9,.9,.9,.2))
}
d <- d[ order(d$x, decreasing=FALSE), ]
result <- d[1,]
for(i in seq_len(nrow(d))[-1] ) {
if( d$y[i] < result$y[nrow(result)] ) {
result <- rbind(result, d[i,]) # inefficient
}
}
points(result, cex=2, pch=15)