我创建了一个多面图facet_wrap
,并且我想更改所有面的 y 轴的中断。
这是我当前的情节:
ggplot( mtcars , aes(x=mpg, y=wt, color=as.factor(cyl) )) +
geom_point(size=3) +
facet_wrap(~cyl,scales = "free_y") +
theme(legend.position="none")
Run Code Online (Sandbox Code Playgroud)
这是我想要的 y 轴中断:
p = ggplot(data=mtcars, aes(x=mpg, y=wt)) +
geom_point(size=3) +
theme_classic()
ymax <- ceiling(max(mtcars$wt))
p + scale_y_continuous(breaks = c(0, ymax), expand = c(0, 0)) + expand_limits(y = ymax)
Run Code Online (Sandbox Code Playgroud)