| 42333 |
ripley |
1 |
% File src/library/graphics/man/spineplot.Rd
|
|
|
2 |
% Part of the R package, http://www.R-project.org
|
| 59039 |
ripley |
3 |
% Copyright 1995-2007 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 35517 |
hornik |
6 |
\name{spineplot}
|
| 56186 |
murdoch |
7 |
\alias{spineplot}
|
| 35517 |
hornik |
8 |
\alias{spineplot.default}
|
|
|
9 |
\alias{spineplot.formula}
|
|
|
10 |
\title{Spine Plots and Spinograms}
|
|
|
11 |
\description{
|
|
|
12 |
Spine plots are a special cases of mosaic plots, and can be seen as
|
|
|
13 |
a generalization of stacked (or highlighted) bar plots. Analogously,
|
|
|
14 |
spinograms are an extension of histograms.
|
|
|
15 |
}
|
|
|
16 |
\usage{
|
|
|
17 |
spineplot(x, \dots)
|
| 36102 |
ripley |
18 |
|
| 35517 |
hornik |
19 |
\method{spineplot}{default}(x, y = NULL,
|
| 44243 |
ripley |
20 |
breaks = NULL, tol.ylab = 0.05, off = NULL,
|
|
|
21 |
ylevels = NULL, col = NULL,
|
|
|
22 |
main = "", xlab = NULL, ylab = NULL,
|
| 36102 |
ripley |
23 |
xaxlabels = NULL, yaxlabels = NULL,
|
| 48612 |
ripley |
24 |
xlim = NULL, ylim = c(0, 1), axes = TRUE, \dots)
|
| 36102 |
ripley |
25 |
|
| 55392 |
ripley |
26 |
\method{spineplot}{formula}(formula, data = NULL,
|
| 44243 |
ripley |
27 |
breaks = NULL, tol.ylab = 0.05, off = NULL,
|
|
|
28 |
ylevels = NULL, col = NULL,
|
|
|
29 |
main = "", xlab = NULL, ylab = NULL,
|
| 36102 |
ripley |
30 |
xaxlabels = NULL, yaxlabels = NULL,
|
| 48612 |
ripley |
31 |
xlim = NULL, ylim = c(0, 1), axes = TRUE, \dots,
|
| 36102 |
ripley |
32 |
subset = NULL)
|
| 35517 |
hornik |
33 |
}
|
|
|
34 |
\arguments{
|
|
|
35 |
\item{x}{an object, the default method expects either a single variable
|
| 36102 |
ripley |
36 |
(interpreted to be the explanatory variable) or a 2-way table. See
|
|
|
37 |
details.}
|
| 35517 |
hornik |
38 |
\item{y}{a \code{"factor"} interpreted to be the dependent variable}
|
| 36102 |
ripley |
39 |
\item{formula}{a \code{"formula"} of type \code{y ~ x} with a single
|
| 61433 |
ripley |
40 |
dependent \code{"factor"} and a single explanatory variable.}
|
| 35517 |
hornik |
41 |
\item{data}{an optional data frame.}
|
| 40281 |
ripley |
42 |
\item{breaks}{if the explanatory variable is numeric, this controls how
|
| 35517 |
hornik |
43 |
it is discretized. \code{breaks} is passed to \code{\link{hist}} and can
|
|
|
44 |
be a list of arguments.}
|
|
|
45 |
\item{tol.ylab}{convenience tolerance parameter for y-axis annotation.
|
|
|
46 |
If the distance between two labels drops under this threshold, they are
|
|
|
47 |
plotted equidistantly.}
|
|
|
48 |
\item{off}{vertical offset between the bars (in per cent). It is fixed to
|
|
|
49 |
\code{0} for spinograms and defaults to \code{2} for spine plots.}
|
| 41355 |
hornik |
50 |
\item{ylevels}{a character or numeric vector specifying in which order
|
|
|
51 |
the levels of the dependent variable should be plotted.}
|
| 35517 |
hornik |
52 |
\item{col}{a vector of fill colors of the same length as \code{levels(y)}.
|
| 61433 |
ripley |
53 |
The default is to call \code{\link{gray.colors}}.}
|
| 35517 |
hornik |
54 |
\item{main, xlab, ylab}{character strings for annotation}
|
| 35533 |
hornik |
55 |
\item{xaxlabels, yaxlabels}{character vectors for annotation of x and y axis.
|
|
|
56 |
Default to \code{levels(y)} and \code{levels(x)}, respectively for the
|
| 35599 |
hornik |
57 |
spine plot. For \code{xaxlabels} in the spinogram, the breaks are
|
|
|
58 |
used.}
|
| 61433 |
ripley |
59 |
\item{xlim, ylim}{the range of x and y values with sensible defaults.}
|
| 48612 |
ripley |
60 |
\item{axes}{logical. If \code{FALSE} all axes (including those giving
|
|
|
61 |
level names) are suppressed.}
|
| 35517 |
hornik |
62 |
\item{\dots}{additional arguments passed to \code{\link{rect}}.}
|
| 35600 |
hornik |
63 |
\item{subset}{an optional vector specifying a subset of observations
|
|
|
64 |
to be used for plotting. }
|
| 35517 |
hornik |
65 |
}
|
|
|
66 |
\details{
|
| 36816 |
ripley |
67 |
\code{spineplot} creates either a spinogram or a spine plot. It can
|
|
|
68 |
be called via \code{spineplot(x, y)} or \code{spineplot(y ~ x)} where
|
|
|
69 |
\code{y} is interpreted to be the dependent variable (and has to be
|
|
|
70 |
categorical) and \code{x} the explanatory variable. \code{x} can be
|
|
|
71 |
either categorical (then a spine plot is created) or numerical (then a
|
|
|
72 |
spinogram is plotted). Additionally, \code{spineplot} can also be
|
|
|
73 |
called with only a single argument which then has to be a 2-way table,
|
|
|
74 |
interpreted to correspond to \code{table(x, y)}.
|
| 61433 |
ripley |
75 |
|
| 36816 |
ripley |
76 |
Both, spine plots and spinograms, are essentially mosaic plots with
|
|
|
77 |
special formatting of spacing and shading. Conceptually, they plot
|
|
|
78 |
\eqn{P(y | x)} against \eqn{P(x)}. For the spine plot (where both
|
|
|
79 |
\eqn{x} and \eqn{y} are categorical), both quantities are approximated
|
|
|
80 |
by the corresponding empirical relative frequencies. For the
|
|
|
81 |
spinogram (where \eqn{x} is numerical), \eqn{x} is first discretized
|
| 40284 |
ripley |
82 |
(by calling \code{\link{hist}} with \code{breaks} argument) and then
|
| 36816 |
ripley |
83 |
empirical relative frequencies are taken.
|
| 61433 |
ripley |
84 |
|
| 36816 |
ripley |
85 |
Thus, spine plots can also be seen as a generalization of stacked bar
|
|
|
86 |
plots where not the heights but the widths of the bars corresponds to
|
|
|
87 |
the relative frequencies of \code{x}. The heights of the bars then
|
|
|
88 |
correspond to the conditional relative frequencies of \code{y} in
|
|
|
89 |
every \code{x} group. Analogously, spinograms extend stacked
|
|
|
90 |
histograms.
|
| 35517 |
hornik |
91 |
}
|
|
|
92 |
\value{
|
|
|
93 |
The table visualized is returned invisibly.
|
|
|
94 |
}
|
|
|
95 |
\seealso{
|
|
|
96 |
\code{\link{mosaicplot}}, \code{\link{hist}}, \code{\link{cdplot}}
|
|
|
97 |
}
|
|
|
98 |
\references{
|
|
|
99 |
Friendly, M. (1994), Mosaic displays for multi-way contingency tables.
|
|
|
100 |
\emph{Journal of the American Statistical Association}, \bold{89},
|
|
|
101 |
190--200.
|
|
|
102 |
|
|
|
103 |
Hartigan, J.A., and Kleiner, B. (1984), A mosaic of television ratings.
|
|
|
104 |
\emph{The American Statistician}, \bold{38}, 32--35.
|
|
|
105 |
|
|
|
106 |
Hofmann, H., Theus, M. (2005), \emph{Interactive graphics for visualizing
|
|
|
107 |
conditional distributions}, Unpublished Manuscript.
|
|
|
108 |
|
|
|
109 |
Hummel, J. (1996), Linked bar charts: Analysing categorical data graphically.
|
|
|
110 |
\emph{Computational Statistics}, \bold{11}, 23--33.
|
|
|
111 |
}
|
|
|
112 |
\author{
|
|
|
113 |
Achim Zeileis \email{Achim.Zeileis@R-project.org}
|
|
|
114 |
}
|
|
|
115 |
\examples{
|
|
|
116 |
## treatment and improvement of patients with rheumatoid arthritis
|
|
|
117 |
treatment <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2),
|
|
|
118 |
labels = c("placebo", "treated"))
|
|
|
119 |
improved <- factor(rep(c(1, 2, 3, 1, 2, 3), c(29, 7, 7, 13, 7, 21)),
|
| 44243 |
ripley |
120 |
levels = c(1, 2, 3),
|
|
|
121 |
labels = c("none", "some", "marked"))
|
| 35517 |
hornik |
122 |
|
|
|
123 |
## (dependence on a categorical variable)
|
|
|
124 |
(spineplot(improved ~ treatment))
|
|
|
125 |
|
| 35533 |
hornik |
126 |
## applications and admissions by department at UC Berkeley
|
| 35517 |
hornik |
127 |
## (two-way tables)
|
| 36816 |
ripley |
128 |
(spineplot(margin.table(UCBAdmissions, c(3, 2)),
|
|
|
129 |
main = "Applications at UCB"))
|
|
|
130 |
(spineplot(margin.table(UCBAdmissions, c(3, 1)),
|
|
|
131 |
main = "Admissions at UCB"))
|
| 35517 |
hornik |
132 |
|
|
|
133 |
## NASA space shuttle o-ring failures
|
| 36816 |
ripley |
134 |
fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1,
|
|
|
135 |
1, 1, 1, 2, 1, 1, 1, 1, 1),
|
| 35517 |
hornik |
136 |
levels = c(1, 2), labels = c("no", "yes"))
|
| 36816 |
ripley |
137 |
temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70,
|
|
|
138 |
70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81)
|
| 35517 |
hornik |
139 |
|
|
|
140 |
## (dependence on a numerical variable)
|
|
|
141 |
(spineplot(fail ~ temperature))
|
|
|
142 |
(spineplot(fail ~ temperature, breaks = 3))
|
|
|
143 |
(spineplot(fail ~ temperature, breaks = quantile(temperature)))
|
| 41355 |
hornik |
144 |
|
|
|
145 |
## highlighting for failures
|
|
|
146 |
spineplot(fail ~ temperature, ylevels = 2:1)
|
| 35517 |
hornik |
147 |
}
|
|
|
148 |
\keyword{hplot}
|