2017-02-16 143 views
3

我就類似問題開展工作,極座標,作爲已經在這裏討論的連接點: r - ggplot2: connecting points in polar coordinates with a straight lineggplot - 在一條直線

不幸的是,解決辦法是不工作了。

我編寫了一個示例代碼來特別討論我的問題。這是我最後一次嘗試:我使用geom_segment而不是geom_path,最後我將線條放在一個圓圈內。這些線總是朝着零朝向,然後根據給定的位置轉向,而不是直線。

require(grid) 
require(ggplot2) 
set.seed(40); 
Location<-data.frame(Winkel=round(runif(1000,0,24),0)) 
Location$BAD <- Location$Winkel %in% c(seq(7,18)) 
Abschnitte<-c(0:24) 
polar<-data.frame(Winkel2=c(1.5, 2.34, 1.2, 3.45, 1.67, 2.61, 1.11, 13.2), 
       value=c(0.1, 0.03, 0.02, 0.015, 0.01, 0.04, 0.09, 0.06), 
       .Names=c("Winkel2", "value")) 

ggplot(Location, aes(x = Winkel, fill = BAD, y=(..count..)/sum(..count..))) + 
geom_histogram(breaks = seq(0,24), colour = "black") + 
coord_polar(start = 0) + theme_minimal() + 
scale_fill_brewer(type="seq",palette=3) + 
ylab("Percentual allocation time") + 
ggtitle("") + 
scale_x_continuous("", limits = c(0, 24), breaks = Abschnitte, labels = Abschnitte) + 
scale_y_continuous(labels = scales::percent)+ 
geom_segment(data=polar, aes(x=0, y=0, xend=Winkel2, yend=value, fill=NA), 
      arrow=arrow(angle=30,type="closed",length=unit(0.3,"cm"))) 

enter image description here

geom_path仍然是更好的選擇?我嘗試了一些與geom_path有關的事情,但並沒有真正達到我想要的地方。

回答

0

我解決了這個問題,我和想分享我的發現:

我的問題是在這條線:

geom_segment(data=polar, aes(x=0, y=0, xend=Winkel2, yend=value, fill=NA), 

起點X確定的方向,其中的箭頭應該去的第一個地方。例如。如果設置爲0,所有箭頭將首先朝向我的零標記並通過製作曲線轉向其預期的位置。爲了解決這個問題,我必須設置X = Winkel2,從而每個箭頭開始在其個人標誌,並直接進入到最後的位置: