lim0: axis limits with one end at zero

View source: R/lim0.R

lim0R Documentation

axis limits with one end at zero

Description

Calculates the range needed for ylim or xlim in plot, so that axis starts at zero and is extended by 4% at the other end

Usage

lim0(x, f = 1/27, curtail = TRUE)

Arguments

x

Numeric. Vector with values

f

Numeric. Extension factor. DEFAULT: 0.04 as in extendrange used eg. by curve

curtail

Logical. Should the range returned be trimmed by 4%? That way, plotting doesn't need the default par xaxs or yaxs changed. DEFAULT: TRUE

Value

Vector with two values: 0 and by 4

Author(s)

Berry Boessenkool, berry-b@gmx.de, 6.6.2013

References

methods(plot), plot.default. Actually, I found extendrange via plot.function in curve

See Also

The extendrange() utility in package grDevices

Examples


# basic idea:
val <- c(3.2, 1.8, 4.5, 2.8, 0.1, 2.9) # just some numbers
plot(val, ylim=lim0(val) ) # you don't even have to set yaxs="i" ;-)

# "normal" plot:
plot(val)
par("usr")  # -0.076  4.676

# if y-axis is not allowed to go below 0, and we're too lazy to set yaxs="i":
plot(val, ylim=lim0(val) )
round( par("usr")  , digits=5) # 0.00000 4.66296

# with 0.04 extension as claimed by help page (1/27 in source code = 0.037):
plot(val, ylim=lim0(val, f=0.04) )
round( par("usr")  , digits=5) # zero is not included on axis anymore

b <- -val
plot(b)
plot(b, ylim=lim0(b) ) # works with only negative values as well

# can handle only-NA input:
lim0(c(7,NA,NA,NA)[-1])
lim0(c(NA,NA,NA))


berryFunctions documentation built on May 29, 2024, 4:01 a.m.