我试着用躲避位置参数执行一个ggplot2 geom barplot,比较两个不同的条件。然而,如果两个条件中的一个是frequncy 0,而另一个是> 0,则条形图占据了两个位置。所以我想用一个较小的基长来缩短它。这个例子会更容易理解。
和我的代码。
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"))