【问题标题】:R: plot circle with radius = 1 and angle 0-2pi in polar -coordinates?R:在极坐标中绘制半径 = 1 和角度 0-2pi 的圆?
【发布时间】:2012-03-23 10:39:22
【问题描述】:

我在 R 中找到了 plotrix 包,但还没有找到如何在 R 中做这个简单的圆。基本上,我怎样才能做一个半径为 1 和 0:360 度角的极坐标图,生成一个圆?

示例

$$r\cos\left(\frac{2\pi}{3}\left(\frac{3\theta}{2\pi}-\left\lfloor\frac{3\theta}{2 \pi}\right\rfloor\right) -\frac{\pi}{3}\right) = 1$$

可能相关

  1. 尝试绘制上述函数,更多 here,带有此 hack 的 LaTex here 可见。

  2. Draw a circle with ggplot2

  3. Regular polygons in polar coordinates

【问题讨论】:

    标签: r plot


    【解决方案1】:

    在ggplot2中可以轻松获取极坐标图。

    From the ggplot2 website:

    library(ggplot2)    
    
    cxc <- ggplot(mtcars, aes(x = factor(cyl))) + 
               geom_bar(width = 1, colour = "black") 
    
    cxc <- cxc + coord_polar()
    
    print(cxc)
    

    【讨论】:

      【解决方案2】:

      你也可以用几何学做圆

      circle <- function(x, y, rad = 1, nvert = 500, ...){
          rads <- seq(0,2*pi,length.out = nvert)
          xcoords <- cos(rads) * rad + x
          ycoords <- sin(rads) * rad + y
          polygon(xcoords, ycoords, ...)
      }
      
      # asp = 1 due to Hans' comment below- wouldn't let me leave a comment just saying 'thanks'
      plot(-5:5, type="n", xlim = c(-5,5), ylim = c(-5,5), asp = 1)
      circle(0,0,4)
      circle(-1.5,1.5,.5)
      circle(1.5,1.5,.5)
      circle(0,0,1)
      segments(-2,-2,2,-2)
      

      【讨论】:

      • 在调用plot命令的时候最好不要忘记纵横比asp = 1,看它真的是一个圆。
      【解决方案3】:

      您可以使用包circular 进行非常好的循环统计。以下是包中的一个示例:

      require(circular)
      x <- circular(runif(50, 0, 2*pi))
      rose.diag(x, bins = 18, main = 'Uniform Data',col=2)
      points(x)
      

      【讨论】:

        猜你喜欢
        • 2017-02-04
        • 2015-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 1970-01-01
        相关资源
        最近更新 更多