2011-12-26 56 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)页面