问题描述
我有一个带有 X、Y 坐标的数据框,但我需要计算覆盖
Library splancs
有一个 areapl
函数来计算非自相交多边形的面积,例如上面的 convex_hull
.因此,我们可以这样做:
库(splancs)as.matrix(convex_hull) %>% areapl
I have a data frame with X, Y coordinates, but I need to calculate the area that cover all the points in the scatterplotthere is a way to draw a polygon that surround all the points and calculate this area?
This is a convex hull problem. Other questions cover similar territory. We can gather the plotting and area calculation problems here for good measure.
To plot the convex hull of a point cloud, we can use the chull
function:
library(tidyverse)
data <- tibble(x = runif(50), y = runif(50))
convex_hull <- data %>% slice(chull(x, y))
ggplot(data, aes(x = x, y = y)) +
geom_point() +
geom_polygon(data = convex_hull,
alpha = 0.25)
Library splancs
has an areapl
function to calculate the area of a non-selfintersecting polygon, such as the convex_hull
above. Hence, we may do:
library(splancs)
as.matrix(convex_hull) %>% areapl
这篇关于如果我只有 X、Y 坐标,如何计算 R 中多边形的面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!