如何在 R 中 create/enhance 我自己的 radar/polar 图表而不需要额外的包?

How to create/enhance my own radar/polar chart without additional packages in R?

我一直在尝试创建给定多边形顶点矢量的 radar/polar 图表的组合,没有包,但只有基数 R,我真的很难做到。到目前为止,在一些帮助下,我达到了以下几点:

a <- a <- abs(rnorm(5, mean = 4, sd = 2))
names(a) <- LETTERS[1:5]
stars(matrix(a,nrow=1),axes=TRUE, scale=FALSE,col.lines="blue",radius=FALSE)
center <- c(x=2.1, y=2.1) #the starchart for some reason chooses this as a center
half <- seq(0, pi, length.out = 51)
angle=45
for (D in a) {
  Xs <- D * cos(half); Ys <- D * sin(half)
  lines(center["x"] + Xs, center["y"] + Ys, col = "gray", xpd = NA, lty="dashed")
  lines(center["x"] + Xs, center["y"] - Ys, col = "gray", xpd = NA, lty="dashed")
}

这给了我一些东西:

我需要进一步做的是:

所以,最终结果应该是这样的:

我已经尝试过 polygon()symbols() 函数和 par() 图形参数,但我真的很难将它们结合起来...我的问题是我不会了解 stars() 函数绘图坐标选择与我的输入的关系。

不喜欢 stars 功能...所以我用 polygon:

做了一个完整的环岛
polar_chart <- function(values){
  k <- length(values)
  m <- max(values)
  # initialise plot
  plot(1, type="n", xlab="", ylab="", xlim=1.2*m*c(-1,1), ylim=1.2*m*c(-1,1))
  # radial lines & letters
  sapply(k:1, function(x){
    text(1.1*m*cos(-(x-1)*2*pi/k + 2*pi/3), 1.1*m*sin(-(x-1)*2*pi/k + 2*pi/3),
         LETTERS[x], cex = 0.75)
    lines(c(0, m*cos((x-1)*2*pi/k + 2*pi/3)), c(0, m*sin((x-1)*2*pi/k + 2*pi/3)),
          col = "grey",lty="dashed")
    })
  # circles
  aux <- seq(2*pi + 0.1, 0, -0.1)
  sapply(values, function(x) lines(x*cos(aux), x*sin(aux), col = "grey",lty="dashed"))
  # polygon
  x <- values*cos(-(1:k-1)*2*pi/k + 2*pi/3)
  y <- values*sin(-(1:k-1)*2*pi/k + 2*pi/3)
  polygon(c(x, x[1]),c(y, y[1]), col = "red", border = "blue", density = 50)
}

values <- abs(rnorm(5, mean = 4, sd = 2))
polar_chart(values)

和returns如下图: