2

Please consider the following sample polar plot:

library(plotrix)
testlen <- c(rnorm(36)*2 + 5)
testpos <- seq(0, 350, by = 10)
polar.plot(testlen, testpos, main = "Test Polar Plot",
           lwd = 3, line.col = 4, rp.type = "s")

The output

I would like to add lines at angles 30 and 330 as well as 150 and 210 (from the center to the outside). I experimented with the line function but could not get it to work.

Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37
moabit21
  • 639
  • 8
  • 20

2 Answers2

2

The calculations for exact placement are a bit goofy but using your test data

set.seed(15)
testlen<-c(rnorm(36)*2+5)
testpos<-seq(0,350,by=10)
polar.plot(testlen,testpos,main="Test Polar Plot",
    lwd=3,line.col=4,rp.type="s")

You can add lines at 20,150,210,300 with

add.line <- c(30,330, 150,210)/360*2*pi
maxlength <- max(pretty(range(testlen)))-min(testlen)
segments(0, 0, cos(add.line) * maxlength, sin(add.line) * maxlength, 
    col = "red")

And that makes the following plot

highlighted angles on polar plot

MrFlick
  • 195,160
  • 17
  • 277
  • 295
1

You can just use the rp.type = "r" argument and add = TRUE. So, something like

library(plotrix)
set.seed(1)
testlen <- c(rnorm(36)*2 + 5)
testpos <- seq(0,350, by = 10)
polar.plot(testlen, testpos, main = "Test Polar Plot",
           lwd = 3, line.col = 4, rp.type = "s")

followed by

pos <- c(30, 330, 150, 210)
len <- c(10, 10, 10, 10)
polar.plot(lengths = len, polar.pos = pos, 
           radial.lim = c(0, 15),
           lwd = 2, line.col = 2, rp.type = "r", add = TRUE)

yields your desired output.

Output

Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37