Skip to content

Commit c186120

Browse files
committed
Re-add alpha scale
1 parent 14f435d commit c186120

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

R/scale-continuous-alpha.r

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ScaleAlpha <- proto(ScaleContinuous, expr={
2+
doc <- TRUE
3+
common <- NULL
4+
5+
new <- function(., name=NULL, limits=NULL, breaks=NULL, labels=NULL, trans = NULL, to = c(0.1, 1)) {
6+
.super$new(., name=name, limits=limits, breaks=breaks, labels=labels, trans=trans, variable = "alpha", to = to)
7+
}
8+
9+
map <- function(., values) {
10+
rescale(values, .$to, .$input_set())
11+
}
12+
output_breaks <- function(.) .$map(.$input_breaks())
13+
14+
objname <- "alpha"
15+
desc <- "Alpha scale for continuous variable"
16+
17+
icon <- function(.) {
18+
x <- c(0.1, 0.3, 0.5, 0.7, 0.9)
19+
rectGrob(x, width=0.25,
20+
gp=gpar(fill=alpha("black", x), col=NA)
21+
)
22+
23+
}
24+
25+
examples <- function(.) {
26+
(p <- qplot(mpg, cyl, data=mtcars, alpha=cyl))
27+
p + scale_alpha("cylinders")
28+
p + scale_alpha("number\nof\ncylinders")
29+
30+
p + scale_alpha(to = c(0.4, 0.8))
31+
}
32+
})

0 commit comments

Comments
 (0)