2015-05-17 55 views
0

我想使用以下信息創建條形圖。我希望將它分成頂行和缺席/現在。我試過了吧圖和ggplot,但他們提出了錯誤或不正確的信息。謝謝!在每列中創建2個數量的條形圖

LHUM RHUM LRAD RRAD LFEM RFEM LTIB RTIB 
    present absent present absent present present absent present 
    present present absent present present present present present 
    present present present present present present present present 
    present present present present present present present present 
    present present present present present present present present 
    present present present present present present present present 
    present present present absent present present present present 
    present present absent present present present present present 
    present present absent present present present present present 
    present present present absent present present present present 
    present present present absent present present present present 
    present absent present absent present present present present 
    present present present absent present present present present 
    present present present present present absent present absent 

回答

1

從你的問題,我不是100%確定你想要什麼。也許這一點 - 假設你的數據在一個叫做df

的數據幀中,首先使用tidyr將它重新整形爲ggplot longform格式。然後繪製...

library(dplyr) 
library(tidyr) 
df <- df %>% gather(name,value,1:8) 

library(ggplot2) 
ggplot(df, aes(name, color=value, fill=value)) + geom_bar() 

enter image description here

+0

的作品。謝謝@jalapic! – Jackie