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

。_饼干妹妹 提交于 2020-05-27 06:20:32

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/61969752/force-the-origin-to-start-at-0-without-margin-between-data-and-x-axis-in-new-ggp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!