This vignette demonstrates functions in the plot range.

library(shrt)

 

limq

limq provides intervals for defining limits for axes such that the resulting plot capture data within given quantiles. The basic usage takes in a single data vector and quantile delimiters.

data.100 = seq(0, 100)
limq(data.100, quantiles=c(0.01, 0.99))

The resulting range captures data from the 1% quantile to the 99% quantile. In this case, the result is just the output from function quantiles. But limq provides useful functionality through its custom arguments.

Setting argument lim can request the output limit to respect a preset lower or upper limit.

limq(data.100, quantiles=c(0.05, 0.95), lim=c(0, NA))

In this case, the lower quantile is ignored and the function fills in only the value of the missing upper limit.

The function also accepts lists of data and can evaluate liits based on columns in matrices.

data.list = list(M=data.frame(A=0:50, B=-(0:50)),
                 N=data.frame(A=51:100, B=-(51:100)))
limq(data.list, column="A")
limq(data.list, column="B")

It is also possible to prettify the output limits via argument pretty.

limq(seq(3.2, 18.6, by=0.2), quantiles=c(0.05, 0.95), pretty=c(2, 10))

In this case, the lower limit is lowered to the nearest multiple of 2. The upper limit is raised to the nearest multiple of 10. Overall, the interval includes at least the data in the (0.05, 0.95) interval.

 

widen

Creating a plot often starts by specifying a plot range interval. The function widen starts from an existing interval and calculates a related-but-wider one. The default action is to update the interval on both sides by 5%.

widen(c(0, 100))

It is also possible to update the intervals by different amounts on each side, for example keeping it fixed on the left and expanding by large fraction on the right,

widen(c(0, 100), by=c(0, 0.2))

When data is meant to be plotted on a logarithmic scale, the widening of the axes by a percentage is meant to be perceived after a log transformation. The widen function conveniently can calculate the required numerics,

widen(c(1, 100), by=c(0, 0.2), log=TRUE)


tkonopka/shrt documentation built on March 5, 2020, 2:51 p.m.