Title: | Axis Labeling |
---|---|
Description: | Functions which provide a range of axis labeling algorithms. |
Authors: | Justin Talbot, |
Maintainer: | Nuno Sempere <[email protected]> |
License: | MIT + file LICENSE | Unlimited |
Version: | 0.4.3 |
Built: | 2024-11-08 06:26:56 UTC |
Source: | CRAN |
Functions for positioning tick labels on axes
Package: | labeling |
Type: | Package |
Version: | 0.4.3 |
Date: | 2023-08-29 |
License: | Unlimited |
LazyLoad: | yes |
Implements a number of axis labeling schemes, including those compared in An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes by Talbot, Lin, and Hanrahan, InfoVis 2010.
Justin Talbot [email protected]
Heckbert, P. S. (1990) Nice numbers for graph labels, Graphics Gems I, Academic Press Professional, Inc. Wilkinson, L. (2005) The Grammar of Graphics, Springer-Verlag New York, Inc. Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010.
extended
, wilkinson
,
heckbert
, rpretty
,
gnuplot
, matplotlib
,
nelder
, sparks
,
thayer
, pretty
heckbert(8.1, 14.1, 4) # 5 10 15 wilkinson(8.1, 14.1, 4) # 8 9 10 11 12 13 14 15 extended(8.1, 14.1, 4) # 8 10 12 14 # When plotting, extend the plot range to include the labeling # Should probably have a helper function to make this easier data(iris) x <- iris$Sepal.Width y <- iris$Sepal.Length xl <- extended(min(x), max(x), 6) yl <- extended(min(y), max(y), 6) plot(x, y, xlim=c(min(x,xl),max(x,xl)), ylim=c(min(y,yl),max(y,yl)), axes=FALSE, main="Extended labeling") axis(1, at=xl) axis(2, at=yl)
heckbert(8.1, 14.1, 4) # 5 10 15 wilkinson(8.1, 14.1, 4) # 8 9 10 11 12 13 14 15 extended(8.1, 14.1, 4) # 8 10 12 14 # When plotting, extend the plot range to include the labeling # Should probably have a helper function to make this easier data(iris) x <- iris$Sepal.Width y <- iris$Sepal.Length xl <- extended(min(x), max(x), 6) yl <- extended(min(y), max(y), 6) plot(x, y, xlim=c(min(x,xl),max(x,xl)), ylim=c(min(y,yl),max(y,yl)), axes=FALSE, main="Extended labeling") axis(1, at=xl) axis(2, at=yl)
extended
is an enhanced version of Wilkinson's
optimization-based axis labeling approach. It is
described in detail in our paper. See the references.
extended(dmin, dmax, m, Q = c(1, 5, 2, 2.5, 4, 3), only.loose = FALSE, w = c(0.25, 0.2, 0.5, 0.05))
extended(dmin, dmax, m, Q = c(1, 5, 2, 2.5, 4, 3), only.loose = FALSE, w = c(0.25, 0.2, 0.5, 0.05))
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
Q |
set of nice numbers |
only.loose |
if true, the extreme labels will be outside the data range |
w |
weights applied to the four optimization components (simplicity, coverage, density, and legibility) |
vector of axis label locations
Justin Talbot [email protected]
Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010.
Generates Figures 2 and 3 from our paper.
extended.figures(samples = 100)
extended.figures(samples = 100)
samples |
number of samples to use (in the paper we used 10000, but that takes awhile to run). |
produces plots as a side effect
Justin Talbot [email protected]
Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010.
gnuplot's labeling algorithm
gnuplot(dmin, dmax, m)
gnuplot(dmin, dmax, m)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
vector of axis label locations
Justin Talbot [email protected]
Heckbert's labeling algorithm
heckbert(dmin, dmax, m)
heckbert(dmin, dmax, m)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
vector of axis label locations
Justin Talbot [email protected]
Heckbert, P. S. (1990) Nice numbers for graph labels, Graphics Gems I, Academic Press Professional, Inc.
Matplotlib's labeling algorithm
matplotlib(dmin, dmax, m)
matplotlib(dmin, dmax, m)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
vector of axis label locations
Justin Talbot [email protected]
Nelder's labeling algorithm
nelder(dmin, dmax, m, Q = c(1, 1.2, 1.6, 2, 2.5, 3, 4, 5, 6, 8, 10))
nelder(dmin, dmax, m, Q = c(1, 1.2, 1.6, 2, 2.5, 3, 4, 5, 6, 8, 10))
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
Q |
set of nice numbers |
vector of axis label locations
Justin Talbot [email protected]
Nelder, J. A. (1976) AS 96. A Simple Algorithm for Scaling Graphs, Journal of the Royal Statistical Society. Series C., pp. 94-96.
R's pretty algorithm implemented in R
rpretty(dmin, dmax, m = 6, n = floor(m) - 1, min.n = n%/%3, shrink.sml = 0.75, high.u.bias = 1.5, u5.bias = 0.5 + 1.5 * high.u.bias)
rpretty(dmin, dmax, m = 6, n = floor(m) - 1, min.n = n%/%3, shrink.sml = 0.75, high.u.bias = 1.5, u5.bias = 0.5 + 1.5 * high.u.bias)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
n |
number of axis intervals (specify one of
|
min.n |
nonnegative integer giving the
minimal number of intervals. If |
shrink.sml |
positive numeric by a which a default
scale is shrunk in the case when |
high.u.bias |
non-negative numeric, typically
|
u5.bias |
non-negative numeric multiplier favoring
factor 5 over 2. Default and 'optimal': |
vector of axis label locations
Justin Talbot [email protected]
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Sparks' labeling algorithm
sparks(dmin, dmax, m)
sparks(dmin, dmax, m)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
vector of axis label locations
Justin Talbot [email protected]
Sparks, D. N. (1971) AS 44. Scatter Diagram Plotting, Journal of the Royal Statistical Society. Series C., pp. 327-331.
Thayer and Storer's labeling algorithm
thayer(dmin, dmax, m)
thayer(dmin, dmax, m)
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
vector of axis label locations
Justin Talbot [email protected]
Thayer, R. P. and Storer, R. F. (1969) AS 21. Scale Selection for Computer Plots, Journal of the Royal Statistical Society. Series C., pp. 206-208.
Wilkinson's labeling algorithm
wilkinson(dmin, dmax, m, Q = c(1, 5, 2, 2.5, 3, 4, 1.5, 7, 6, 8, 9), mincoverage = 0.8, mrange = max(floor(m/2), 2):ceiling(6 * m))
wilkinson(dmin, dmax, m, Q = c(1, 5, 2, 2.5, 3, 4, 1.5, 7, 6, 8, 9), mincoverage = 0.8, mrange = max(floor(m/2), 2):ceiling(6 * m))
dmin |
minimum of the data range |
dmax |
maximum of the data range |
m |
number of axis labels |
Q |
set of nice numbers |
mincoverage |
minimum ratio between the the data range and the labeling range, controlling the whitespace around the labeling (default = 0.8) |
mrange |
range of |
vector of axis label locations
Ported from Wilkinson's Java implementation with some changes. Changes: 1) m (the target number of ticks) is hard coded in Wilkinson's implementation as 5. Here we allow it to vary as a parameter. Since m is fixed, Wilkinson only searches over a fixed range 4-13 of possible resulting ticks. We broadened the search range to max(floor(m/2),2) to ceiling(6*m), which is a larger range than Wilkinson considers for 5 and allows us to vary m, including using non-integer values of m. 2) Wilkinson's implementation assumes that the scores are non-negative. But, his revised granularity function can be extremely negative. We tweaked the code to allow negative scores. We found that this produced better labelings. 3) We added 10 to Q. This seemed to be necessary to get steps of size 1. It is possible for this algorithm to find no solution. In Wilkinson's implementation, instead of failing, he returns the non-nice labels spaced evenly from min to max. We want to detect this case, so we return NULL. If this happens, the search range, mrange, needs to be increased.
Justin Talbot [email protected]
Wilkinson, L. (2005) The Grammar of Graphics, Springer-Verlag New York, Inc.