在 R 上使用 "chull" 后如何创建凸区域(由线连接)

How to create a convex area (connected by lines) after using "chull" on R

根据包含网球运动员信息的大数据框,我创建了一个仅包含单个运动员反手击球的 df,其中包括姓名、年龄和击球位置的 "x,y" 坐标列。我已经用网球场和拍摄的地方做了一个图形,但是我很难创建凸包。

创建我使用的第一个图形:

Grph <- ggplot() +
  geom_point(BH, mapping = aes(x = x1 - 58.015,y = y1,
             fill = factor(BH$Result)), shape = 21, size = 5) + 
  guides(fill = guide_legend(title = NULL)) +
....

然后我尝试了:

BHF <- chull(BH)

我得到了数字,但无法用外线制作图形。

以下内容对我来说没有意义(是的,我是新手):

X <- matrix(stats::rnorm(2000), ncol = 2)
chull(X)
plot(X, cex = 0.5)
hpts <- chull(X)
hpts <- c(hpts, hpts[1])
lines(X[hpts, ])

我使用的一些子集是:

data_B1 <- subset(full_data, Player == ch_player & Opp == 
ch_opp &Local == match & Type == event1)
data_B2 <- subset(full_data, Player == ch_player & Opp == ch_opp
&Local == match & Type == event2)

创建 substes 后,我使用 rbind 创建了 BH DF

事件 1 是防守反手 事件 2 是进攻反手

BH = data.frame(x = rnorm(2000), y= rnorm(2000))  # create a dummy example data.frame
BHL = chull(BH[, c("x", "y")]) # calculate convex hull for x and y columns
BHL = c(BHL, BHL[1]) # add the first point again at the end, so the path loops back to the beginning

#now plot using geom_path 
ggplot(BH, aes(x,y)) +
  geom_point() +
  geom_path(data=BH[BHL, ])