开发者

R rank points in plot

I have a question about plots. For example we have variable a and b, we plot this in R and you get the point. Now, I want to make a range of best/highest point. Is there a way to generate a ranking in t开发者_运维问答he point? I thought maybe something with mean?

Thanks!

a<- c(1,3,7,5,3,8,4,5,3,6,9,4,2,6,3)
b<- c(5,3,7,2,7,2,5,2,7,3,6,2,1,1,9)
plot(a,b)


Based on your comment to get the positions of the points with the 5 highest b values, use order:

order(b,decreasing=T)[1:5]
[1] 15  3  5  9 11

And you can use this to get the relevant a and b values:

a[order(b,decreasing=T)[1:5]]
[1] 3 7 3 3 9
b[order(b,decreasing=T)[1:5]]
[1] 9 7 7 7 6 

You can use this also to highlight them in the plot:

high <- order(b,decreasing=T)[1:5]
col <- rep("black",length(b))
col[high] <- "red"
plot(a,b,col=col)

R rank points in plot

Note that there is some overplotting here (2 values at (3,7))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜