2012-03-23 71 views
1

我在R中找到了plotrix软件包,但是还找不到如何在R中做这个简单的圆。基本上,我该如何做一个半径为1和0:360度的极坐标图,生成一个圆?R:极坐标中半径为1且角为0-2pi的圆圈?

$$ r \ COS \左(\压裂{2 \ PI} {3} \左(\压裂{3 \ THETA} {2 \ PI} - \左\ lfloor \压裂{3 \ THETA} {2 \ PI} \右\ rfloor \右侧) - \压裂{\ PI} {3} \右)= 1 $$

也许相关

  1. 试图绘制上面的函数,更多here,与此黑客here可见的LaTex。

  2. Draw a circle with ggplot2

  3. Regular polygons in polar coordinates

回答

5

你可以很容易地得到极坐标图中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) 

enter image description here

5

您也可以使用几何

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) 
+4

你最好不要忘记长宽比,'ASP = 1',调用绘图命令时,看到它确实是一个圆。 – 2012-03-23 11:40:35

2

你可以用包circular做的非常漂亮的圆形统计做出圈。下面是从包装的例子之一:

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

enter image description here