【问题标题】:R: How to add highlighted angle lines in polar plots?R:如何在极坐标图中添加突出显示的角度线?
【发布时间】:2014-06-02 22:56:25
【问题描述】:

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

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 功能,但无法让它工作。

【问题讨论】:

    标签: r plotrix


    【解决方案1】:

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

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

    这就是下面的情节

    【讨论】:

      【解决方案2】:

      您可以只使用rp.type = "r" 参数和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)
      

      产生你想要的输出。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-07
        • 2016-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多