2012-03-23 105 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