-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
When creating histogram or bar charts the standard expansion factor of 0.05
creates an unsighty gap between the bars and the x axis.
library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(hp)) +
geom_histogram()
To remove this gap currently one has to add scale_y_continuous(expand = expansion(c(0, 0.05))
to the plot. This is cumbersome to type, easy to forget and hard to grasp for beginners.
I'd love to have a shortcut for that, something like:
scale_y_tight <- function(...) {
scale_y_continuous(expand = expansion(0, 0.05), ...)
}
This is in the same spirit as ylab()
or ylim()
.
Thinking a bit further maybe this could even be an option:
exact_ylim <- function(...) {
scale_y_continuous(limits = c(...), expand = expansion())
}
This would force the axis limits to be exactly those requested which is not the case currently with ylim()
.