2

请考虑以下示例极坐标图:

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")

输出

我想添加角度为 30 和 330 以及 150 和 210(从中心到外部)的线。我尝试了 line 功能,但无法让它工作。

4

2 回答 2

2

精确放置的计算有点愚蠢,但使用您的测试数据

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")

您可以在 20,150,210,300 处添加行

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")

这使得下面的情节

极坐标图上突出显示的角度

于 2014-06-02T14:47:21.680 回答
1

您可以只使用rp.type = "r"参数 and add = TRUE。所以,像

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")

其次是

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)

产生您想要的输出。

输出

于 2014-06-02T14:47:57.330 回答