r - 围绕给定百分比的点绘制圆/凸包

标签 r plot convex-hull ggproto

我有

x=rnorm(100)
y=rnorm(100)
plot(x,y)
abline(h=0); abline(v=0)

从点 (0,0) 向外我想绘制一个轮廓/圆/椭圆/手绘凸包,它包含任何给定百分比的点。

是否有任何函数或包可以自动执行此操作?到目前为止,我已经尝试了以下方法,但我只能通过一些外推和近似得到一个圆。

到目前为止我已经试过了:

#calculate radius
r<- sqrt(x^2+y^2)

df<-data.frame(radius=seq(0,3,0.1), percentage=NA)

#get the percentage of points that have a smaller radius than i
k<-1
for (i in seq(0,3,0.1)){
  df$percentage[k] <- sum(r<i)/length(r)
  k<-k+1
}

#extrapolation function
prox.function<- approxfun(df$percentage, df$radius)


#get the radius of the circle that encloses about 50% of
prox.function(.50)

#draw the circle
library(plotrix)
draw.circle(0,0,prox.function(.50))

enter image description here

最佳答案

包围分数 f 的点的半径是:

f <- 0.5 # use half for this example as in the question
sort(r)[ ceiling(f * length(r)) ]

关于r - 围绕给定百分比的点绘制圆/凸包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301108/

相关文章:

r - 为什么在使用 rmarkdown 和 bookdown 时将外部 Rmd 文件包含在 latex 方程环境中会导致不同的 DOCX 输出?

r - 在 RStudio 中执行 "cannot open the connection"时出现错误 "knit HTML"

wolfram-mathematica - Mathematica中的计算几何包和 “Nontensor object generated”

图中右/左对齐字幕位置

python - 编辑情节 - python

r - 绘制R中quickhull算法给出的凸包(convhulln函数)

c# - 用户绘制圆的凸包

r - 如何测试条件何时在R中返回数字(0)

r - 将单个唯一变量合并到其他相同的行中

c - sleep() 函数未按预期工作