rpolygonr-base-graphics

How to draw circles around polygon/spider chart, without plotting libraries


Without using ggplot2 or other plotting libraries, I would need to draw circles around a polygon/star chart vertices, i.e. each circle with a radius equal to the respective polygon radius. You can see an example here:

enter image description here

d1 <- 1:4
names(d1) <- LETTERS[1:4]
stars(matrix(d1,nrow=1),axes=TRUE, scale=FALSE,radius=TRUE, frame.plot=TRUE,labels = dimnames(d1)[[1]])
grid()[enter image description here][1]

I understand I should combine the stars() with the symbols(), polygon() functions or par(...) graphics, but honestly, I am new to these kind of plotting techniques and very lost on how to combine functions and arguments


Solution

  • I don't know of any functions in base R that do circles for you, but you can concoct them manually.

    center <- c(x=2.1, y=2.1) # probably a better way
    half <- seq(0, pi, length.out = 51)
    for (D in d1) {
      Xs <- D * cos(half); Ys <- D * sin(half)
      lines(center["x"] + Xs, center["y"] + Ys, col = "gray", xpd = NA)
      lines(center["x"] + Xs, center["y"] - Ys, col = "gray", xpd = NA)
    }
    

    stars with concentric circles

    Notes: