簡體   English   中英

R:以極坐標繪制半徑為1且角度為0-2pi的圓?

[英]R: plot circle with radius = 1 and angle 0-2pi in polar -coordinates?

我在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. 嘗試繪制以上功能, 此處顯示更多, 此處可見此黑客的LaTex。

  2. 用ggplot2畫一個圓

  3. 極坐標中的規則多邊形

您可以在ggplot2中輕松獲得極坐標圖。

從ggplot2網站:

library(ggplot2)    

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

cxc <- cxc + coord_polar()

print(cxc)

在此處輸入圖片說明

您也可以使用幾何圖形制作圓

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)

您可以使用package circle進行非常好的循環統計。 以下是該包中的示例之一:

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM