2011-12-26 62 views
1

我需要使用R和GGPLOT2參照線添加到我的密度圖。添加geom_hline密度積coord_polar()

因爲我用極座標,這應該在我的情節中間的圓圈。我使用geom_hline(yintercept = .5),但當我添加coord_polar()時,沒有線條出現在我的情節中。

這是我的代碼。

ggplot(flights_sample2, aes(x = radians, fill = factor(nf, levels = c(8:0)))) + 
    geom_bar(binwidth = pi/18, position = "fill") + 
    scale_x_continuous(limits = c(0, 2*pi), breaks = c(0,pi/2, pi, 3*pi/2), 
              labels = c("N", "E", "S", "W")) + 
    coord_polar() + 
    xlim(0,2*pi) + 
    geom_hline(yintercept = .5) 

有什麼建議嗎?

+0

你舉的例子是不可重現。 – 2011-12-26 23:01:41

回答

2

如果您第一次設置了geom_line參考,然後添加coord_polar(),你可以得到一個參考圓:

xx=seq(0,2*pi,length=10) 
yy=rep(2,10) 
g <- ggplot(flights_sample2, aes(x = radians, fill = factor(nf, levels = c(8:0)))) + 
    geom_bar(binwidth = pi/18, position = "fill") + 
    scale_x_continuous(limits = c(0, 2*pi), breaks = c(0,pi/2, pi, 3*pi/2), 
              labels = c("N", "E", "S", "W")) + 
     xlim(0,2*pi) + 
    geom_hline(aes(x=xx, y=yy)) 

g+coord_polar() 

顯然,這不是與您的數據和代碼進行測試,但它與合作例如,在幫助(coord_polar)頁面