簡體   English   中英

位置在ggplot2中不閃避barplot

[英]position does not dodge for barplot in ggplot2

關於這種類型的問題有很多帖子,我已經嘗試了很多,但是position =“ dodge”不會使劇情中的條變得避開。 我的數據如下:

+----------------------------------------------------+
|              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 |
+----------------------------------------------------+

每次我得到這個: 使用ggplot2的barplot ,並且您可以看到位置不會閃避。 我想要這樣的東西: 使用Excel的barplot這是我嘗試過的代碼:

    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)

代碼的其他變體不斷給我帶來錯誤,甚至沒有繪制出曲線圖。 誰能給我指出正確的方向。 我對SO的第一個問題是,如果代碼或表的格式不正確,請您道歉。 我可以在Excel中輕松地做到這一點,但是正在學習R,我只想知道R為什么不產生類似的圖? 謝謝!

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

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)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM