Consider some sample data where a level does not occur:
dat <- data.frame(sex = c("F","M","F"),
status = c("Pregnant","Not pregnant","Not pregnant"),
frequency = c(25,100,75))
In the sample data males cannot become pregnant so they have no data.
I would like to plot the data using ggplot2
in R
using this code:
library(ggplot2)
p <- ggplot(dat,aes(x=status,y=frequency,fill=sex))+
geom_bar(stat = "identity",position="dodge")
print(p)
I get this output:
As you can see, the bar for female and pregnant is wider than the other bars. My question is how can I suppress the bar widening to have the bars the same width?