When I plot a bar graph in ggplot2 I would like to reduce the space between the bottom of the bars and the x-axis to 0, yet keep the space above the bars and the plot box. I have a hack to do it below. It's dirty and I want to be clean again. Is there a way to achieve this behavior without the dirty little hack?
Default (desired space above but don't want space below bars):
ggplot(mtcars, aes(x=as.factor(carb))) +
geom_bar()
Use expand (undesired 0 space above but got the 0 space below bars):
ggplot(mtcars, aes(x=as.factor(carb))) +
geom_bar() +
scale_y_continuous(expand = c(0,0))
Dirty Hack (I like it but its.. well, dirty):
ggplot(mtcars, aes(x=as.factor(carb))) +
geom_bar() +
scale_y_continuous(expand = c(0,0)) +
geom_text(aes(x=1, y=10.3, label="Stretch it"), vjust=-1)
coord_cartesian
to much hardcoding as well? – Henrikexpand()
into a list of upper limit expansion and lower limit expansion. – Gregor Thomas