2

I have a simple bar graph which x is the levels of a category variable 1 - 9, and z is the count of each level. But there is a distance at the bottom (marked in red), which I want to remove. I wasn't able to find helpful tips online. Could anyone help me with it? Thank you in advance!

ggplot(data = my_data,aes(x = factor(degree)), stat = "count") + geom_bar()

Bar Graph

divibisan
  • 11,659
  • 11
  • 40
  • 58
Da Daidai
  • 25
  • 1
  • 4

1 Answers1

4

The expand= argument in the scale_* function controls the extra space around the edges of a plot.

ggplot(data = mtcars,aes(x = factor(cyl)), stat = "count") +
    geom_bar() +
    scale_y_discrete()

enter image description here

ggplot(data = mtcars,aes(x = factor(cyl)), stat = "count") +
    geom_bar() +
    scale_y_discrete(expand = c(0,0))

enter image description here

divibisan
  • 11,659
  • 11
  • 40
  • 58
  • 1
    Also see the new `expand_scale()` function, which is useful when you only want to remove the extra space at the bottom of the bars and not the top. – aosmith Sep 13 '18 at 17:04