2

I want to make a plot where all the bars are the same width. In the following dataset, I have faceted in two categories. When one of the categories is absent in the discrete x variable, the bar width doubles to compensate.

Is there a way to override this, so that absence in one of the categories comes out as a 'zero' i.e. no bar rather than doubling the bar width?

dataset csv file here

install.packages("ggplot2")
install.packages("scales")

library("ggplot2")
library("scales")

  ggplot(p, aes(x=gene, fill=origin)) +
  geom_histogram(binwidth=.5, position="dodge") +     geom_histogram(binwidth=.5, position="dodge", color="black", show_guide=FALSE) +
  ylab("No. of SNPs") +
  scale_y_continuous(breaks=pretty_breaks(n=6)) +
  scale_fill_manual(values=c("blue","gold")) +
  theme(panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank(),
        axis.title = element_text(size=16,face="bold", colour="black"), 
        axis.title.x = element_blank(), ##remove xaxis title
        axis.text.y = element_text(size=14,colour="black"),
        axis.text.x = element_text(angle=90,vjust=0.5, size=14,colour="black"),
        legend.text= element_text(size = 16),
        legend.position="top") +
  guides(fill=guide_legend(title=NULL))

0 Answers0