Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (72 sloc) 2.494 kb
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
1 #' Use values without scaling.
2 #'
abfcd2f @hadley Documentation improvements for website
authored
3 #' @name scale_identity
0d6fd95 @hadley Documentation tweaks
authored
4 #' @param ... Other arguments passed on to \code{\link{discrete_scale}} or
5 #' \code{\link{continuous_scale}}
4304af8 @hadley Doc tweaks for continuous scales
authored
6 #' @param guide Guide to use for this scale - defaults to \code{"none"}.
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
7 #' @examples
8 #' colour <- c("red", "green", "blue", "yellow")
9 #' qplot(1:4, 1:4, fill = colour, geom = "tile")
10 #' qplot(1:4, 1:4, fill = colour, geom = "tile") + scale_fill_identity()
1244716 @hadley Trim whitespace
authored
11 #'
357322f @hadley Train identity scales when they have a guide.
authored
12 #' # To get a legend guide, specify guide = "legend"
1244716 @hadley Trim whitespace
authored
13 #' qplot(1:4, 1:4, fill = colour, geom = "tile") +
357322f @hadley Train identity scales when they have a guide.
authored
14 #' scale_fill_identity(guide = "legend")
15 #' # But you'll typically also need to supply breaks and labels:
1244716 @hadley Trim whitespace
authored
16 #' qplot(1:4, 1:4, fill = colour, geom = "tile") +
17 #' scale_fill_identity("trt", labels = letters[1:4], breaks = colour,
357322f @hadley Train identity scales when they have a guide.
authored
18 #' guide = "legend")
1244716 @hadley Trim whitespace
authored
19 #'
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
20 #' # cyl scaled to appropriate size
21 #' qplot(mpg, wt, data = mtcars, size = cyl)
1244716 @hadley Trim whitespace
authored
22 #'
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
23 #' # cyl used as point size
24 #' qplot(mpg, wt, data = mtcars, size = cyl) + scale_size_identity()
b2accd6 @wch More doc fixes for R CMD check
wch authored
25 NULL
abfcd2f @hadley Documentation improvements for website
authored
26
27 #' @rdname scale_identity
b2accd6 @wch More doc fixes for R CMD check
wch authored
28 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
29 scale_colour_identity <- function(..., guide = "none") {
30 identity_scale(discrete_scale("colour", "identity", identity_pal(), ..., guide = guide))
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
31 }
e82e737 @hadley Use new roxygen features to better document scales
authored
32
33 #' @rdname scale_identity
34 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
35 scale_fill_identity <- function(..., guide = "none") {
36 identity_scale(discrete_scale("fill", "identity", identity_pal(), ..., guide = guide))
1244716 @hadley Trim whitespace
authored
37
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
38 }
e82e737 @hadley Use new roxygen features to better document scales
authored
39
40 #' @rdname scale_identity
41 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
42 scale_shape_identity <- function(..., guide = "none") {
c388795 @hadley Identity scale doesn't need to train.
authored
43 identity_scale(continuous_scale("shape", "identity", identity_pal(), ..., guide = guide))
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
44 }
e82e737 @hadley Use new roxygen features to better document scales
authored
45
46 #' @rdname scale_identity
47 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
48 scale_linetype_identity <- function(..., guide = "none") {
49 identity_scale(discrete_scale("linetype", "identity", identity_pal(), ..., guide = guide))
1244716 @hadley Trim whitespace
authored
50
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
51 }
6198457 @hadley Add ggplot
authored
52
e82e737 @hadley Use new roxygen features to better document scales
authored
53 #' @rdname scale_identity
54 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
55 scale_alpha_identity <- function(..., guide = "none") {
56 identity_scale(continuous_scale("alpha", "identity", identity_pal(), ..., guide = guide))
1244716 @hadley Trim whitespace
authored
57
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
58 }
e82e737 @hadley Use new roxygen features to better document scales
authored
59
60 #' @rdname scale_identity
61 #' @export
1cefea6 @kohske scale-identity: fix a bug around legend specification (thanks to Dennis ...
kohske authored
62 scale_size_identity <- function(..., guide = "none") {
63 identity_scale(continuous_scale("size", "identity", identity_pal(), ..., guide = guide))
e2dd04c @hadley Fixes to scale_identity so can be used for testing
authored
64 }
65
66 identity_scale <- function(x) {
67 structure(x, class = c("identity", class(x)))
68 }
69
3c63ff7 @hadley Convert from @S3method to @export
authored
70 #' @export
e2dd04c @hadley Fixes to scale_identity so can be used for testing
authored
71 scale_map.identity <- function(scale, x) {
72 if (is.factor(x)) {
73 as.character(x)
74 } else {
75 x
76 }
b7d7bfc @hadley Major revamp of scales to use new scales package.
authored
77 }
3c63ff7 @hadley Convert from @S3method to @export
authored
78 #' @export
c388795 @hadley Identity scale doesn't need to train.
authored
79 scale_train.identity <- function(scale, x) {
357322f @hadley Train identity scales when they have a guide.
authored
80 # do nothing if no guide, otherwise train so we know what breaks to use
81 if (scale$guide == "none") return()
82 NextMethod()
c388795 @hadley Identity scale doesn't need to train.
authored
83 }
Something went wrong with that request. Please try again.