Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (71 sloc) 2.603 kB
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
1 #' Differentiation related aesthetics: linetype, size, shape
1244716 @hadley Trim whitespace
authored
2 #'
3 #' This page demonstrates the usage of a sub-group
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
4 #' of aesthetics; linetype, size and shape.
1244716 @hadley Trim whitespace
authored
5 #'
d34d4ad @hadley Fix documentation ordering
authored
6 #' @name aes_linetype_size_shape
1244716 @hadley Trim whitespace
authored
7 #' @aliases linetype size shape
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
8 #' @examples
9 #'
10 #' # Line types should be specified with either an integer, a name, or with a string of
1e28092 @bbolker various doc/comment typos
bbolker authored
11 #' # an even number (up to eight) of hexadecimal digits which give the lengths in
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
12 #' # consecutive positions in the string.
13 #' # 0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash
14 #'
15 #' # Data
16 #' df <- data.frame(x = 1:10 , y = 1:10)
a04742b @hrbrmstr Nearly done with qplot cleanup
hrbrmstr authored
17 #' f <- ggplot(df, aes(x, y))
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
18 #' f + geom_line(linetype = 2)
19 #' f + geom_line(linetype = "dotdash")
20 #
1244716 @hadley Trim whitespace
authored
21 #' # An example with hex strings, the string "33" specifies three units on followed
22 #' # by three off and "3313" specifies three units on followed by three off followed
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
23 #' # by one on and finally three off.
24 #' f + geom_line(linetype = "3313")
25 #'
26 #' # Mapping line type from a variable
3d8b389 @hadley Checking examples. Up to geom_blank.Rd
authored
27 #' library(plyr)
28 #' library(reshape2)
29 #' rescale01 <- function(x) (x - min(x)) / diff(range(x))
30 #' ec_scaled <- data.frame(
1244716 @hadley Trim whitespace
authored
31 #' date = economics$date,
32 #' colwise(rescale01)(economics[, -(1:2)]))
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
33 #' ecm <- melt(ec_scaled, id = "date")
a04742b @hrbrmstr Nearly done with qplot cleanup
hrbrmstr authored
34 #' ggplot(ecm, aes(date, value)) +
35 #' geom_line(aes(linetype = variable))
1244716 @hadley Trim whitespace
authored
36 #'
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
37 #' # Size examples
1244716 @hadley Trim whitespace
authored
38 #' # Should be specified with a numerical value (in millimetres),
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
39 #' # or from a variable source
40 #' p <- ggplot(mtcars, aes(wt, mpg))
41 #' p + geom_point(size = 4)
42 #' p + geom_point(aes(size = qsec))
a04742b @hrbrmstr Nearly done with qplot cleanup
hrbrmstr authored
43 #' p + geom_point(size = 2.5) +
44 #' geom_hline(yintercept = 25, size = 3.5)
1244716 @hadley Trim whitespace
authored
45 #'
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
46 #' # Shape examples
47 #' # Shape takes four types of values: an integer in [0, 25],
48 #' # a single character-- which uses that character as the plotting symbol,
49 #' # a . to draw the smallest rectangle that is visible (i.e., about one pixel)
50 #' # an NA to draw nothing
51 #' p + geom_point()
52 #' p + geom_point(shape = 5)
53 #' p + geom_point(shape = "k", size = 3)
54 #' p + geom_point(shape = ".")
55 #' p + geom_point(shape = NA)
56 #'
57 #' # Shape can also be mapped from a variable
58 #' p + geom_point(aes(shape = factor(cyl)))
1244716 @hadley Trim whitespace
authored
59 #'
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
60 #' # A look at all 25 symbols
61 #' df2 <- data.frame(x = 1:5 , y = 1:25, z = 1:25)
a04742b @hrbrmstr Nearly done with qplot cleanup
hrbrmstr authored
62 #' s <- ggplot(df2, aes(x, y))
63 #' s + geom_point(aes(shape = z), size = 4) +
64 #' scale_shape_identity()
b5edd86 @JakeRuss Style change to geom_point; new aes page for differentiation aesthetics
JakeRuss authored
65 #' # While all symbols have a foreground colour, symbols 19-25 also take a
66 #' # background colour (fill)
1244716 @hadley Trim whitespace
authored
67 #' s + geom_point(aes(shape = z), size = 4, colour = "Red") +
3d8b389 @hadley Checking examples. Up to geom_blank.Rd
authored
68 #' scale_shape_identity()
1244716 @hadley Trim whitespace
authored
69 #' s + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black") +
3d8b389 @hadley Checking examples. Up to geom_blank.Rd
authored
70 #' scale_shape_identity()
4bcc38a @hadley Add missing newlines
authored
71 NULL
Something went wrong with that request. Please try again.