仅设置 ggplot 限制的下限 [英] set only lower bound of a limit for 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屋!