user1471980
user1471980

Reputation: 10626

How do you get rid of empty spaces between y-axis and first bar in ggplot2

I am using ggplot2 to graph some bar charts. I do see some empty spaces between first bar and y-axis and the same on the far most right of the bar chart as well. Is there a way to get rid of the empty spaces in ggplot2?

Upvotes: 2

Views: 1881

Answers (1)

jrara
jrara

Reputation: 16981

For example like this:

library(ggplot2)
data(diamonds)
p.dia <- ggplot(data = diamonds, mapping = aes(x = clarity))
p + scale_y_continuous(expand = c(0,0)) + scale_x_discrete(expand = c(0,0))

enter image description here

Upvotes: 3

Related Questions