2016-09-29 36 views
2

下午好,ggplot訂單數據圓形陰謀

我想知道如果有人能指出我正確的方向來解決循環陰謀問題。我有一些樣本數據,我正在嘗試製作類似於以下圖片的內容,僅顯示8周的定向數據,風險值從非常低的風險(在數據中表示爲「0」到高風險表示爲「4」集。

這是在油漆做,我試圖創造一些與R.以下爲8周的數據圖。該圖只顯示了各15度的方向,以最低的風險每週最高。enter image description here 的例子表示以下顏色:

白色=非常低,綠色=低,黃色=中,橙=高和紅色=很高

我試圖攝製儘管類似這樣的設計,但如上圖所示,無論每個15度區間的星期數如何,都需要整理出最低到最高的分辨率。

到目前爲止我的代碼讓我:

enter image description here

什麼,我努力修復是:

  1. 從極高到極低的每個15度報告的順序在數據上沒有任何空白(例如,如果2周的數據僅存在2周 - 圖中的0-15度)

  2. 傳說從非常低到非常高的

的順序我已經試過scale_fill_manual但我覺得我不使用這一權利。

我的代碼是迄今:

ggplot(dat, aes(Arc, "", fill=Risk)) + 
    geom_bar(width=14.5, stat='identity', colour=("grey90")) + 
    scale_fill_manual(values = c("Red", "orange","green","yellow","white")) + 
    coord_polar(start= 0)+ 
    labs(x = '', y = '') + 

    theme_bw() + 

    theme(panel.border = element_blank(), 
     legend.key = element_blank(), 
     axis.ticks = element_blank(), 
     axis.text.y = element_blank(), 
     axis.text.x = element_blank(), 
     panel.grid = element_blank(), 
     legend.position="bottom") 

和我的樣本輸入數據是:

dput(dat) 
structure(list(Arc = c(7.5, 22.5, 37.5, 52.5, 67.5, 82.5, 97.5, 
112.5, 127.5, 142.5, 157.5, 172.5, 187.5, 202.5, 217.5, 232.5, 
247.5, 262.5, 277.5, 292.5, 307.5, 322.5, 337.5, 352.5, 7.5, 
22.5, 37.5, 52.5, 67.5, 82.5, 97.5, 112.5, 127.5, 142.5, 157.5, 
172.5, 187.5, 202.5, 217.5, 232.5, 247.5, 262.5, 277.5, 292.5, 
307.5, 322.5, 337.5, 352.5, 7.5, 22.5, 37.5, 52.5, 67.5, 82.5, 
97.5, 112.5, 127.5, 142.5, 157.5, 172.5, 187.5, 202.5, 217.5, 
232.5, 247.5, 262.5, 277.5, 292.5, 307.5, 322.5, 337.5, 352.5, 
7.5, 22.5, 37.5, 52.5, 67.5, 82.5, 97.5, 112.5, 127.5, 142.5, 
157.5, 172.5, 187.5, 202.5, 217.5, 232.5, 247.5, 262.5, 277.5, 
292.5, 307.5, 322.5, 337.5, 352.5, 7.5, 22.5, 37.5, 52.5, 67.5, 
82.5, 97.5, 112.5, 127.5, 142.5, 157.5, 172.5, 187.5, 202.5, 
217.5, 232.5, 247.5, 262.5, 277.5, 292.5, 307.5, 322.5, 337.5, 
352.5, 7.5, 22.5, 37.5, 52.5, 67.5, 82.5, 97.5, 112.5, 127.5, 
142.5, 157.5, 172.5, 187.5, 202.5, 217.5, 232.5, 247.5, 262.5, 
277.5, 292.5, 307.5, 322.5, 337.5, 352.5, 7.5, 22.5, 37.5, 52.5, 
67.5, 82.5, 97.5, 112.5, 127.5, 142.5, 157.5, 172.5, 187.5, 202.5, 
217.5, 232.5, 247.5, 262.5, 277.5, 292.5, 307.5, 322.5, 337.5, 
352.5, 7.5, 22.5, 37.5, 52.5, 67.5, 82.5, 97.5, 112.5, 127.5, 
142.5, 157.5, 172.5, 187.5, 202.5, 217.5, 232.5, 247.5, 262.5, 
277.5, 292.5, 307.5, 322.5, 337.5, 352.5), RiskV = c(0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 3L, 
3L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 2L, 3L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 2L, 2L, 2L, 1L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 3L, 3L, 3L, 
3L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 2L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"Low", "Medium", "Very High", 
    "Very Low"), class = "factor")), .Names = c("Arc", "RiskV", 
"week", "Risk"), class = "data.frame", row.names = c(NA, -192L 
)) 

如果有人能指出我在哪裏,我錯了,這將是巨大的,在此先感謝

+3

如果我加上'水平= C( 「非常高」, 「高」, 「中」, 「低」, 「極低」)'後'類=「因子」'當定義風險在dat,我設置的因素水平的順序,並得到正確的順序與正確的顏色相關的圖例。 – Haboryme

+0

@Haboryme,謝謝你的評論。我只是想知道我該如何設置課程?我之前沒有使用過這個 – Achak

+1

對於風險類別是因素,可以用因子()來完成。例如,風險=因素(c(「低」,「低」,「高」,「中」),水平= c(「低」,「中」,「高」))。這是否回答你關於課堂的問題? – Haboryme

回答

1

爲了有一個很好的顯示,我刪除了具有「非常低」風險的值

newdata=dat%>%filter(RiskV>=1) 

我改變了關卡的級別,以便「非常低」的級別不會混淆圖例。

newdata$Risk<-factor(newdata$Risk,levels=c("Very High","High","Medium","Low")) 

和情節:

ggplot(newdata, aes(Arc)) + 
    geom_bar(width=14.5, stat='identity',position = "stack",colour=("grey90"),aes(y=1,fill=Risk)) + 
    coord_polar()+ 
scale_fill_manual(values = c("Red", "orange","green","yellow")) 
+0

感謝@Haboryme,這回答了我所有的問題,並且在我們討論過的時候完美地工作! – Achak