4

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

jpsmith
  • 11,023
  • 5
  • 15
  • 36
choabf
  • 57
  • 5

1 Answers1

2

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:

  • I don't know off-hand how the center-point should be calculated, I chose that point using locator(1); not being familiar with stars, there may be a better way to determine this programmatically and more accurately;
  • The first lines(.) draws the upper semi-circle; the second draws the lower.
  • The xpd=NA is to preclude clipping due to the drawing margin. It may not be necessary in your "real" data. See ?par for more details on this.
  • Though it may be difficult to detect here, the gray circles are drawn on top of the stars plot, which might be an aesthetic compromise. The only way around that is to plot the circles first. To do this, draw the first semicircle first with plot(..., type="l") and then add the remainder as expected, and only then run stars(..., add=TRUE).
r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Thank you so much! This solves a lot of work so far. Wish you a great weekend ahead! – choabf Dec 17 '21 at 14:45
  • Thank you r2evans. I will surely do. I am trying to find a way to edit my question. Not sure if that is possible. I would like to add some more specifications to the question, if I am not being greedy. Would you advise that I post a new question? – choabf Dec 17 '21 at 19:35
  • Some editing is fine, but feature-creep/spiral-questions are discouraged. What are you trying to add? – r2evans Dec 17 '21 at 19:36
  • Some pedantic job: adding the radii of the circles passing through all the vertices, adding the name labels at the end of the radii, outside of the circle and coloring the polygon area with some alpha....If packages were allowed, I would have probably found my way by now, but base R is k!ll!ng me. I think I might post a new question, sounds more appropriate. Thank you for your time. – choabf Dec 17 '21 at 19:39
  • I think that's a fair way forward, thank you for understanding. Please don't forget to accept if/when this one is resolved. – r2evans Dec 17 '21 at 19:41