繁体   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