2016-04-15 79 views
0

這個類型的問題已經有很多帖子,我嘗試了很多,但是position =「dodge」並不能躲避情節中的酒吧。我的數據如下:ggplot2的位置不會躲避barplot

+----------------------------------------------------+ 
|    Sps_wk0_wk7 Prot_Delta Seq_Delta  | 
+----------------------------------------------------+ 
| 1 Prevotella_copri_DSM_18205   25 -47.214 | 
| 2 Dorea_longicatena_DSM_13814   -2 12.925 | 
| 3  Acidaminococcus_sp_D21   6  8.328 | 
+----------------------------------------------------+ 

,每次我得到這個:barplot using ggplot2和你所看到的位置也不閃躲。 我想是這樣的:barplot using Excel 這是我曾嘗試代碼:

ggplot(proteogenomic_diff, aes(x=Sps_wk0_wk7))+ 
    geom_bar(aes(y=Prot_Delta, group=Prot_Delta, fill="blue"), stat="identity", width=0.10)+ 
    geom_bar(aes(y=Seq_Delta, group=Seq_Delta, position="dodge", fill="Orange"), stat="identity", width=0.10) 

代碼的其他變化不斷給我的錯誤甚至不產生陰謀。任何人都可以請我指出正確的方向。 我的第一個問題很抱歉,如果代碼或表格沒有正確格式化。我可以在Excel中輕鬆做到這一點,但是我正在學習R,我只想知道R爲什麼不生成類似的情節? 謝謝!

回答

0

您需要首先將數據融入長格式:

library(reshape2) 
proteogenomic_diff.m <- melt(proteogenomic_diff) 

ggplot(proteogenomic_diff.m, aes(x = Sps_wk0_wk7, y = value, group = variable, fill = variable)) + 
    geom_bar(stat="identity", position = position_dodge(width = .1), width = .1) 

enter image description here