Force the origin to start at 0 without margin between data and x axis in new ggplot theme
Asked Answered
C

1

4

Based on this question Force the origin to start at 0 I want to implement this into a new created theme and not just as a default setting.

data(iris)
ggplot(iris, aes(x = Species)) + 
  geom_bar() +
  scale_y_continuous(expand = expansion(mult = c(0, 0.05)))

How can I do this without defining it every single plot?

requested result

Center answered 23/5, 2020 at 9:8 Comment(1)
It's an open issue in the ggplot2 issue tracker: github.com/tidyverse/ggplot2/issues/2691Novick
F
3

As far as I know this not possible via theme(). But you can define a wrapper around scale_y_continuous like so

library(ggplot2)

data(iris)

scale_y_origin <- function(...) {
  scale_y_continuous(expand = expansion(mult = c(0, 0.05)), ...)
}

ggplot(iris, aes(x = Species)) + 
  geom_bar() +
  scale_y_origin()
Frech answered 23/5, 2020 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.