仅设置 ggplot 限制的下限 [英] set only lower bound of a limit for ggplot

查看:11
本文介绍了仅设置 ggplot 限制的下限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以只设置连续缩放的下限?我想让我的所有图都基于 0,而无需指定上限.

例如

+ scale_y_continuous(minlim=0)

解决方案

您可以使用 expand_limits

ggplot(mtcars, aes(wt, mpg)) + geom_point() + expand_limits(y=0)

以下是两者的比较:

  • 没有expand_limits

  • 使用expand_limits

ggplot2 的 1.0.0 版本开始,您只能指定一个限制,而另一个限制是通过将第二个限制设置为 NA 通常来确定的.这种方法将允许轴范围的扩展和截断.

ggplot(mtcars, aes(wt, mpg)) + geom_point() +scale_y_continuous(limits = c(0, NA))

通过 ylim(c(0, NA)) 指定它会得到一个相同的数字.

Is it possible to only set the lower bound of a limit for continuous scale? I want to make all my plots 0 based without needing to specify the upper limit bound.

e.g.

+ scale_y_continuous(minlim=0)

解决方案

You can use expand_limits

ggplot(mtcars, aes(wt, mpg)) + geom_point() + expand_limits(y=0)

Here is a comparison of the two:

  • without expand_limits

  • with expand_limits

As of version 1.0.0 of ggplot2, you can specify only one limit and have the other be as it would be normally determined by setting that second limit to NA. This approach will allow for both expansion and truncation of the axis range.

ggplot(mtcars, aes(wt, mpg)) + geom_point() +
  scale_y_continuous(limits = c(0, NA))

specifying it via ylim(c(0, NA)) gives an identical figure.

这篇关于仅设置 ggplot 限制的下限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆