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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…