2015-10-20 80 views
1

我想繪製一束點的極座標圖。因此,這裏是使用ggplot2我的代碼:ggplot2:在極座標圖中缺少座標值

x <- runif(min = -pi, max = pi, n = 100) 
y <- runif(n = 100) 
df1 <- data.frame(x = x, y = y) 
library(ggplot2) 
ggplot(df1, aes(y = y, x = x)) + 
    geom_point() + 
    ylim(0,1) + 
    theme_light() + 
    theme(legend.position="none", panel.border=element_blank(), 
     axis.title = element_blank(), axis.text.y = element_blank()) + 
    scale_x_continuous(labels = paste(seq(-180,180,30)), 
        breaks = seq(-pi,pi, length=13)) + 
    coord_polar() 

我碰到下面的情節:

enter image description here

然而,正如我們所看到的,180軸丟失。我如何得到這個? (我不想讓y的尺度同時出現,或者如果是這樣,那麼能夠控制在那裏顯示的東西。)

有什麼建議嗎?

回答

2

您可以在pi上添加一條垂直線,但使其透明。如果您使用xintercept=c(-pi,pi),您將獲得-180/180作爲標籤。

ggplot(df1, aes(y = y, x = x)) + 
    geom_point() + 
    ylim(0,1) + 
    theme_light() + 
    geom_vline(aes(xintercept=pi), col='transparent') + 
    theme(legend.position="none", panel.border=element_blank(), 
     axis.title = element_blank(), axis.text.y = element_blank()) + 
    scale_x_continuous(labels = paste(seq(-180,180,30)), 
        breaks = seq(-pi,pi, length=13)) + 
    coord_polar() 

enter image description here