I can\'t figure out how to use expand()
within scale_x_discrete()
to expand a categorical x-axis so that placing a label to the right of points won
Since I'm facing the same problem... I found expand_limits(...)
quite useful here:
dat <- data.frame(x= c('a', 'b', 'c'), y= 1:3)
ggplot(data= dat, aes(x= x, y= y)) +
geom_point() +
expand_limits(x= c(-1, 5))
Or, to avoid hardcoding the limits:
expand_limits(x= c(-1, length(levels(dat$x)) + 2))
(With ggplot2_3.1.0
)