2015-10-16 106 views
4

我正在繪製circular庫中rose.diag函數的角度分佈圖。輸入數據是輻射。我MWE代碼是用圓形包創建半個極座標圖(玫瑰圖)

library(circular); 
    dat<-read.csv(file.choose(),header=F); 
    data=unlist(dat); 
    rose.diag(data, bins=24) 

,我得到這個圖: enter image description here

我很感興趣,只顯示部分數據,從-pi/2到pi/2,而長度最大滴答等於圓的半徑的長度,如下所示: enter image description here

任何幫助將不勝感激!

編輯

正如#lawyeR建議這裏是與數據的樣本代碼:

library(circular); 
    data<- c(-0.188,-0.742,-0.953,-0.948,-0.953,-1.187,-0.9327200,-0.855,- 0.024,1.303,-1.041,-1.068,-1.066,1.442,1.150,0.965,0.665,0.649,0.984,-1.379,-0.584,-0.573,-0.357,-0.237,-0.287,-0.486,-0.783,-0.298,0.849,1.088,-1.003,-0.952,-0.776,-0.811,-0.880); 
    rose.diag(data, bins=24); 
+0

爲什麼不輸入數據以便人們可以更好地幫助您? – lawyeR

+0

感謝您的回答。我已編輯帖子以添加數據樣本。 – michltm

+0

好。我編輯了你的問題並添加了另一個標籤,希望能夠吸引一兩個答案。 – lawyeR

回答

4

或許你可以先畫不分配半圓,使用默認打印功能。然後填寫沒有圈子的分佈:

library(circular) 

data<- c(-0.188,-0.742,-0.953,-0.948,-0.953,-1.187,-0.9327200,-0.855,- 0.024,1.303,-1.041,-1.068,-1.066,1.442,1.150,0.965,0.665,0.649,0.984,-1.379,-0.584,-0.573,-0.357,-0.237,-0.287,-0.486,-0.783,-0.298,0.849,1.088,-1.003,-0.952,-0.776,-0.811,-0.880) 

freq <- diff(colSums(outer(data %% (2*pi), (1:24)*pi/12,"<")))/length(data) 
r.max <- sqrt(max(freq)) 

#----------------------------------------------------------------- 
# Plot the half circle: 

lab.width <- 0.15*r.max 
lab.height <- 0.15*r.max 

plot(c(-r.max,r.max), c(0,0), 
     axes=FALSE, 
     ylim=c(0,r.max+lab.height), 
     xlim=c(-r.max-lab.width,r.max+lab.width), 
     xlab="", ylab="", type="l") 

for (i in 0:(5*12-1)) 
{ 
    psi <- i*pi/(5*12) 
    x1 <- r.max*cos(psi) 
    y1 <- r.max*sin(psi) 
    x2 <- r.max*cos(psi+pi/(5*12)) 
    y2 <- r.max*sin(psi+pi/(5*12)) 

    lines(c(x1,x2), c(y1,y2), type="l") 

    if (i %% 5 == 0) { lines(x1*c(1,0.95), y1*c(1,0.95), type="l") } 
} 

par(cex=2.0) 

text(x = c(-r.max,0,r.max), 
     y = c(0,r.max,0), 
     labels = c("-pi/2","0","pi/2"), 
     pos = c(2,3,4)) 

#------------------------------------------------------------ 
# Plot the distribution, but without the circle: 

rose.diag(data, 
      bins = 24, 
      rotation = "clock", 
      tcl.text = NA, 
      ticks = FALSE, 
      zero = pi/2, 
      control.circle = circle.control(col="white"), 
      add = TRUE) 

enter image description here

+0

這是一個絕妙的主意!謝謝你的幫助。我還有最後一個問題:在外部圓上添加-pi/2,0,pi/2最好的方法是什麼? – michltm

+0

我編輯了我的答案。你可以使用'text'來添加標籤。 – mra68

+0

非常感謝您寶貴的幫助,這樣很好! – michltm