Expand numeric range
Arguments
- x
numeric
vector, orlist
ofnumeric
vectors. The input is converted to a range usingrange(x, na.rm=TRUE)
to ensure noNA
values are included. Note that this step will force the range to be in ascending order.- expand_fraction
numeric
value indicating the fraction of the range defined bydiff(range(x, na.rm=TRUE))
to add to the total range. Whenexpand_fraction
has only one value, it is applied across the whole range, which means each side is extended by half theexpand_fraction
. Whenexpand_fraction
contains two values, it is applied in order to the low, then high side of the numeric range, and each fullexpand_range
value is applied.- minimum_range
numeric
value indicating the minimum range of the output, useful when the input has zero range, for example ifx=c(10, 10)
.- ...
additional arguments are ignored.
Value
numeric
vector, or when input x
is list
the
output will also be a list
of numeric
vectors.
The numeric vector will contain the range after
expansion.
Details
This function takes a numeric
range (or numeric vector
and calculates its range) and expands this range by
a fraction given by expand_fraction
.
When the input range is zero, the minimum absolute range
can be given by minimum_range
.
The input may be a list
that contains numeric
vectors,
in which case the list
will be iterated to produce an
expanded range for each numeric
vector. Each numeric
vector is expanded independently.
This function is intended to be a simple technique to expand x-axis and y-axis ranges of a graphical plot.
See also
Other venndir utility:
curate_venn_labels()
,
make_color_contrast()
,
make_venn_combn_df()
,
make_venn_test()
,
match_list()
,
modify_venndir_overlap()
,
nudge_venndir_label()
,
plot,Venndir,ANY-method
,
print_color_df()
,
shrink_df()
,
three_point_angle()
,
venndir_legender()
,
venndir_to_df()
Examples
x <- c(0, 10);
# expand the total range by 0.1
expand_range(x, 0.1);
#> [1] -0.5 10.5
# the original range is 10 units
diff(x);
#> [1] 10
# the expanded range is 11 units
diff(expand_range(x, 0.1));
#> [1] 11
# expand one side but not the other
expand_range(x, c(0.1, 0));
#> [1] -1 10
# this new range is 11 units
diff(expand_range(x, c(0.1, 0)))
#> [1] 11
# input with no range is extended to some minimum value
expand_range(1, minimum_range=1)
#> [1] 0.5 1.5
expand_range(1, minimum_range=c(1, 0))
#> [1] 0 1
# list input is iterated, for example xlim, ylim
xlim <- c(1, 10)
ylim <- c(1, 100)
expand_range(list(xlim=xlim, ylim=ylim))
#> $xlim
#> [1] 0.55 10.45
#>
#> $ylim
#> [1] -3.95 104.95
#>