簡體   English   中英

縮短 ggplot2 dodge_position 中的條形圖

[英]Shorten barplot in ggplot2 dodge_position

我嘗試使用閃避 position 參數比較兩種不同的條件來執行 ggplot2 幾何條形圖。 但是,如果兩個條件之一的頻率為 0,而另一個條件 > 0,則條形圖同時占用 position。 所以我想用更小的基長來縮短它。 這個例子會更容易理解:

在此處輸入圖像描述

和我的代碼:

library(ggplot2)

ggplot(df_plot2, aes(x=Var1, y=perc,fill=TYPE))+
  geom_bar(stat = 'identity', position='dodge')+
  labs(y="Percentage", x="Gene Ontologies") +
  theme_classic()+
  scale_fill_manual(name = "Transcripts of:", values=c("#ff6c00","grey20")) +
  theme(axis.text.x = element_text(angle = 60, hjust = 1), text = element_text(size = 16))

非常感謝!

您必須將preserve = single選項添加到position_dodge

geom_bar(position = position_dodge2(preserve = "single"))

https://ggplot2.tidyverse.org/reference/position_dodge.html

暫無
暫無

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

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