I tried to perform a ggplot2 geom barplot using the dodge position parameter comparing two different conditions. However, if one of the two condition has frequncy 0, while the other one is > 0, the bar occupies both position. So I would like to shorten it with a smaller base length. This example will be easier to understand:
and my code:
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))
Thanks a lot!
You have to add the preserve = single
option to position_dodge
geom_bar(position = position_dodge2(preserve = "single"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.