Set only lower limit limit for ggplot

Is it possible to set the lower limit of the limit for continuous scale? I want to make all my graphs 0 without having to specify an upper limit.

eg.

+ scale_y_continuous(minlim=0) 
+54
r ggplot2
Jun 26 '12 at 18:46
source share
3 answers

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

Starting from version 1.0.0 of ggplot2 , you can specify only one limit and have another, as was usually determined by setting the second limit to NA . This approach will allow both the expansion and truncation of the range of axes.

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

asking it with ylim(c(0, NA)) gives an identical digit.

+76
Jun 26 '12 at 19:14
source share

How about using aes(ymin=0) , as in:

 ggplot(mtcars, aes(wt, mpg)) + geom_point() + aes(ymin=0) 
+9
Jun 26 2018-12-12T00:
source share

I do not think you can do this directly. But as a workaround, you can imitate how ggplot2 defines the upper limit:

 scale_y_continuous(limits=c(0, max(mydata$y) * 1.1)) 
-one
Jun 26 '12 at 18:55
source share



All Articles