R: Draw a "ladder of powers" plot, plotting each of several...
ladder
R Documentation
Draw a "ladder of powers" plot, plotting each of several powers
of y against the same powers of x.
Description
Draw a "ladder of powers" plot, plotting each of several powers
of y against the same powers of x. The powers are
result <- data.frame(-1/x, -1/sqrt(x), log(x), sqrt(x), x, x^2)
names(result) <- c(-1, -.5, 0, .5, 1, 2)
Usage
ladder(formula.in, data=sys.parent(),
main.in="Ladders of Powers",
panel.in=panel.cartesian,
xlab=deparse(formula.in[[3]]),
ylab=deparse(formula.in[[2]]),
scales=list(alternating=if.R(s=TRUE, r=FALSE),
labels=FALSE, ticks=FALSE, cex=.6),
par.strip.text=list(cex=.6),
cex=.5, pch=16, between=list(x=.3, y=.3),
dsx=xlab,
dsy=ylab,
ladder.function=ladder.f,
strip.number=if.R(r=2, s=1),
strip.names,
strip.style=1,
strip,
oma=c(0,0,0,0), ## S-Plus
axis3.line=.61,
layout=c(length(tmp$x.power), length(tmp$y.power)),
axis.key.padding = 10, ## R right axis
key.axis.padding = 10, ## R top axis
useOuter=TRUE, ## R useOuterStrips(combineLimits(result))
...)
ladder3(x, y,
dsx=deparse(substitute(x)),
dsy=deparse(substitute(y)),
ladder.function=ladder.f)
ladder.f(x, name.prefix="")
ladder.fstar(x, name.prefix="")
strip.ladder(which.given,
which.panel,
var.name,
factor.levels,
shingle.intervals,
par.strip.text=trellis.par.get("add.text"),
strip.names=c(TRUE,TRUE),
style=1,
...)
Arguments
formula.in
A formula with exactly one variable on each side.
data
data.frame
main.in
main title for xyplot
panel.in
panel.cartesian has many arguments in addition
to the arguments in panel.xyplot. Any replacement
panel function must have those argument names, even if it
doesn't do anything with them.
xlab, ylab
Trellis arguments, default to right- and left-sides
of the formula.in.
strip
Strip function. Our default is strip.ladder
(see below). The other viable argument value is FALSE.
cex, pch, between, scales, layout
arguments for xyplot.
dsx, dsy
Names to be used as level names in
ladder.function for the generated factor distinguishing the
powers. They default to xlab, ylab. For long variable names,
an abbreviated name here will decrease clutter in the ladder of powers
plot. These names are not visible in the plot when
strip=FALSE.
ladder.function
function to use to create data.frame of powers
of input variable.
name.prefix
Base name used for column names of powers. The
default is empty (""). An alternative must include
the power symbol "^", for example, "abc^".
strip.number
Number of strip labels in each panel of the display.
0: no strip labels; 1: one strip label of the form y^p ~ x^q;
2: two strip labels of the form ylab: y^p and xlab: x^q,
where p and q are the powers returned by ladders;
y and x are the arguments dsy and dsx.
useOuter
logical, defaults to TRUE. In R, this implies
that strip.number is forced to 2 and that the
resulting "trellis" object will be sent through useOuterStrips(combineLimits(result)).
This argument is ignored by S-Plus.
strip.style
style argument to strip.
oma
argument to par in S-Plus.
...
other arguments to xyplot.
axis3.line
extra space to make the top axis align with the top
of the top row of panels. Trial and error to choose a good value.
We always print the strip.names
in style=1. Multicolored styles are too busy.
Details
The ladder function uses panel.cartesian which is
defined differently in R (using grid graphics) and S-Plus (using
traditional graphics). Therefore the fine control over appearance
uses different arguments or different values for the same arguments.
Value
ladder returns a "trellis" object.
The functions ladder.fstar and ladder.f take an input
vector x of non-negative values and construct a data.frame by
taking the input to the powers c(-1, -.5, 0, .5, 1, 2), one
column per power. ladder.f uses the simple powers and
ladder.fstar uses the scaled Box–Cox transformation.
ladder.fstar
ladder.fstar
notation
(x^p - 1)/p
(x^p - 1)/p
p
(1/x - 1)/(-1)
(1/x - 1)/(-1)
-1.0
(1/sqrt(x)-1)/(-.5)
(1/sqrt(x)-1)/(-.5)
-0.5
log(x)
log(x)
0.0
((sqrt(x)-1)/.5)
((sqrt(x)-1)/.5)
0.5
x-1
x-1
1.0
(x^2 - 1)/2
(x^2 - 1)/2
2.0
ladder3 takes two vectors as arguments. It returns a
data.frame with five columns:
X, Y: data to be plotted. The column X contains the data
from the input x taken to all the powers and aligned with the
similarly expanded column Y.
x, y: symbolic labeling of the power corresponding to X,Y.
group: result from pasting the labels in x, y with *
between them.
Author(s)
Richard M. Heiberger <rmh@temple.edu>
References
Heiberger, Richard M. and Holland, Burt (2004b).
Statistical Analysis and Data Display: An Intermediate Course
with Examples in S-Plus, R, and SAS.
Springer Texts in Statistics. Springer.
ISBN 0-387-40270-5.
Hoaglin, D.~C., Mosteller, F., and Tukey, J.~W., editors (1983).
Understanding Robust and Exploratory Data Analysis.
Wiley.
Box, G. E.~P. and Cox, D.~R. (1964).
An analysis of transformations.
J. Royal Statist Soc B, 26:211–252.
See Also
panel.cartesian
Examples
data(tv)
## default
## R: outer strip labels
## S-Plus: one strip label per panel (too full for this example, see below)
ladder(life.exp ~ ppl.per.phys, data=tv,
main="Ladder of Powers for Life Expectancy and People per Physician")
## Not run:
## one strip label
if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=1, useOuter=FALSE,
dsx="ppp", dsy="le"),
s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=1,
dsx="ppp", dsy="le")) ## S-Plus default
## two strip labels
if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=2, useOuter=FALSE),
s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=2,
axis3.line=1.2))
## outer strip labels
if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, useOuter=TRUE), ## R default
s={}) ## S-Plus not available
## no strip labels (probably silly, but possible)
if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=0, useOuter=FALSE),
s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=0,
axis3.line=0))
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(HH)
Loading required package: lattice
Loading required package: grid
Loading required package: latticeExtra
Loading required package: RColorBrewer
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS
Attaching package: 'TH.data'
The following object is masked from 'package:MASS':
geyser
Loading required package: gridExtra
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/HH/ladder.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ladder
> ### Title: Draw a "ladder of powers" plot, plotting each of several powers
> ### of y against the same powers of x.
> ### Aliases: ladder ladder3 ladder.f ladder.fstar strip.ladder
> ### Keywords: hplot dplot manip
>
> ### ** Examples
>
> data(tv)
>
> ## default
> ## R: outer strip labels
> ## S-Plus: one strip label per panel (too full for this example, see below)
> ladder(life.exp ~ ppl.per.phys, data=tv,
+ main="Ladder of Powers for Life Expectancy and People per Physician")
>
> ## Not run:
> ##D ## one strip label
> ##D if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=1, useOuter=FALSE,
> ##D dsx="ppp", dsy="le"),
> ##D s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=1,
> ##D dsx="ppp", dsy="le")) ## S-Plus default
> ##D
> ##D ## two strip labels
> ##D if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=2, useOuter=FALSE),
> ##D s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=2,
> ##D axis3.line=1.2))
> ##D
> ##D ## outer strip labels
> ##D if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, useOuter=TRUE), ## R default
> ##D s={}) ## S-Plus not available
> ##D
> ##D ## no strip labels (probably silly, but possible)
> ##D if.R(r=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=0, useOuter=FALSE),
> ##D s=ladder(life.exp ~ ppl.per.phys, data=tv, strip.number=0,
> ##D axis3.line=0))
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>