extendrange
Numbers a bit outside the range of a vector

Description

Expands range(x) symmetrically around mean(x).

Usage

extendrange(x, r = range(x, na.rm = TRUE), f = 0.05)

Arguments

x a vector of numbers or dates (or other classes for which range(x) and x+diff(x) work).
r a vector of length two giving the range of x. If this is supplied, then x itself is ignored. Otherwise, it is the range of x, ignoring missing values.
f a number: typically small. The range is expanded (or reduced, if f<0), by a factor of 1+f.

Details

If x has only one unique value, then extendrange(x) is that value, twice.
Value
returns a two-long vector given by r + c(-1,1) * diff(r) * 0.05.
Examples
extendrange(c(1,2,3,20))
extendrange(as.Date(c("2015-09-01", "2016-01-15", "2015-12-30")), f=0.02)
Package grDevices version 6.1.1-7
Package Index