1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{scale_x_discrete}
\alias{scale_x_discrete}
\alias{scale_y_discrete}
\title{Discrete position.}
\usage{
scale_x_discrete(..., expand = waiver())
scale_y_discrete(..., expand = waiver())
}
\arguments{
\item{...}{common discrete scale parameters: \code{name}, \code{breaks},
\code{labels}, \code{na.value}, \code{limits} and \code{guide}. See
\code{\link{discrete_scale}} for more details}
\item{expand}{a numeric vector of length two giving multiplicative and
additive expansion constants. These constants ensure that the data is
placed some distance away from the axes.}
}
\description{
You can use continuous positions even with a discrete position scale -
this allows you (e.g.) to place labels between bars in a bar chart.
Continuous positions are numeric values starting at one for the first
level, and increasing by one for each level (i.e. the labels are placed
at integer positions). This is what allows jittering to work.
}
\examples{
\donttest{
qplot(cut, data=diamonds, stat="bin")
qplot(cut, data=diamonds, geom="bar")
# The discrete position scale is added automatically whenever you
# have a discrete position.
(d <- qplot(cut, clarity, data=subset(diamonds, carat > 1), geom="jitter"))
d + scale_x_discrete("Cut")
d + scale_x_discrete("Cut", labels = c("Fair" = "F","Good" = "G",
"Very Good" = "VG","Perfect" = "P","Ideal" = "I"))
d + scale_y_discrete("Clarity")
d + scale_x_discrete("Cut") + scale_y_discrete("Clarity")
# Use limits to adjust the which levels (and in what order)
# are displayed
d + scale_x_discrete(limits=c("Fair","Ideal"))
# you can also use the short hand functions xlim and ylim
d + xlim("Fair","Ideal", "Good")
d + ylim("I1", "IF")
# See ?reorder to reorder based on the values of another variable
qplot(manufacturer, cty, data=mpg)
qplot(reorder(manufacturer, cty), cty, data=mpg)
qplot(reorder(manufacturer, displ), cty, data=mpg)
# Use abbreviate as a formatter to reduce long names
qplot(reorder(manufacturer, cty), cty, data=mpg) +
scale_x_discrete(labels = abbreviate)
}
}
\seealso{
Other position scales: \code{\link{scale_x_continuous}},
\code{\link{scale_x_log10}},
\code{\link{scale_x_reverse}},
\code{\link{scale_x_sqrt}},
\code{\link{scale_y_continuous}},
\code{\link{scale_y_log10}},
\code{\link{scale_y_reverse}},
\code{\link{scale_y_sqrt}};
\code{\link{scale_x_datetime}},
\code{\link{scale_y_datetime}};
\code{\link{scale_x_date}}, \code{\link{scale_y_date}}
}
|