ggplot2 bar plot, no space between bottom of geom and x axis keep space above

前端 未结 6 1136
逝去的感伤
逝去的感伤 2020-11-30 00:37

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.

6条回答
  •  日久生厌
    2020-11-30 00:51

    I might be missing what you really want, but without using geom_text hack you can still set the limits

    ggplot(mtcars, aes(x = as.factor(carb))) + 
        geom_bar() + 
        scale_y_continuous(expand = c(0, 0), limits = c(0, 10.3)) 
    
    # marginally cleaner
    

提交回复
热议问题