forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale-discrete-grey.r
44 lines (33 loc) · 1.36 KB
/
scale-discrete-grey.r
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
ScaleGrey <- proto(ScaleColour, expr={
doc <- TRUE
common <- c("colour", "fill")
aliases <- "scale_color_grey"
new <- function(., name=NULL, variable, start = 0.2, end = 0.8, limits=NULL, breaks = NULL, labels=NULL, formatter = identity, legend = TRUE) {
b_and_l <- check_breaks_and_labels(breaks, labels)
.$proto(name=name, .input=variable, .output=variable, start=start, end=end, limits = limits, breaks = b_and_l$breaks, .labels = b_and_l$labels, formatter=formatter, legend = legend)
}
output_set <- function(.) {
grey.colors(length(.$input_breaks()), start = .$start, end = .$end)
}
max_levels <- function(.) Inf
# Documentation -----------------------------------------------
objname <- "grey"
desc <- "Sequential grey colour scale"
details <- "<p>Based on ?gray.colors</p>"
desc_params <- list(
"start" = "starting grey colour (between 0 and 1)",
"end" = "ending grey colour (between 0 and 1)"
)
icon <- function(.) {
rectGrob(c(0.1, 0.3, 0.5, 0.7, 0.9), width=0.21,
gp=gpar(fill=gray(seq(0, 1, length=5)), col=NA)
)
}
examples <- function(.) {
p <- qplot(mpg, wt, data=mtcars, colour=factor(cyl))
p + scale_colour_grey()
p + scale_colour_grey(end = 0)
# You may want to turn off the pale grey background with this scale
p + scale_colour_grey() + theme_bw()
}
})