2016-07-29 102 views
3

我想要一個圓形條形圖,像圖所示:極地柱狀圖中,與最裏面的圓空基於R

enter image description here 但現在,我只有: enter image description here

爲了使這個我用在R中的以下代碼:

require(ggplot2) 
ggplot(PolarPlot,aes(x,y, 
        fill=x))+ 
     geom_bar(width=1,stat="identity")+ 
     coord_polar() + xlab("")+ylab("")+ 
    theme(legend.position = "none" , axis.text.y = element_blank() , 
     axis.ticks = element_blank() 

有人可以告訴我需要做什麼修改才能獲得我想要的圖嗎?

的數據如下:

PolarPlot <- structure(list(x = structure(1:7, .Label = c("Class1", "Class2", 
    "Class3", "Class4", "Class5", "Class6", "Class7"), class = "factor"), 
    y = c(2L, 8L, 17L, 56L, 28L, 7L, 2L)), .Names = c("x", "y"), 
    class = "data.frame", row.names = c(NA, -7L)) 
+1

看起來我們錯過了您的數據。對於這種類型的問題,SO需要一個完全可重複的例子,以便我們可以幫助您。 –

+0

我添加了數據。它只是一個簡單的頻率表。 – 204

+1

謝謝。他們會說要以可複製的方式發佈它(這意味着你可以將它讀入R)。你可能想使用'dput(the_data)'。 –

回答

3

通過先創建一個柱狀圖中,然後將其轉換爲極座標(這是罰款)出示你的陰謀。如果你想讓條形圖不能從極座標圖的中心開始,那麼你需要確保它們不在條形圖的底部開始。

我的意思是最簡單的解釋是通過實際顯示它。首先,我創建了柱狀圖中相同的方式,你做什麼,但我延長y軸來達到負值:

p <- ggplot(PolarPlot, aes(x, y, fill=x)) + 
     geom_bar(width=1,stat="identity") + 
     xlab("") + ylab("") + 
     theme(legend.position = "none" , axis.text.y = element_blank() , 
      axis.ticks = element_blank()) + 
     scale_y_continuous(limits = c(-50, 60)) 

enter image description here

當我切換到極座標,差距在他

p + coord_polar() 

enter image description here

您可以在修改的間隙的尺寸:該條形圖的下端在極座標圖的中心被轉換成間隙該中心通過使用中用於limits的值。