Skip to content

Commit d799623

Browse files
committed
Clean up of continuous colour scale code
1 parent 5428484 commit d799623

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ ggplot2 0.8.5 (2009-XX-XX) ----------------------------------------
3030
added - this could cause problems if you layer modified the plot.
3131
(Implements #28)
3232
* scale_shape_discrete and scale_size_continuous added to scales to match
33-
naming convention of all other scales (Fixes #47)
33+
naming convention of all other scales (Fixes #47)
34+
* scale_colour_gradient, scale_colour_gradient2 & scale_colour_gradientn now
35+
have formatter argument to match scale_continuous

R/scale-continuous-colour.r

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
ScaleGradient <- proto(ScaleContinuous, expr={
22
aliases <- c("scale_colour_continuous", "scale_fill_continuous", "scale_color_continuous", "scale_color_gradient")
33

4-
new <- function(., name=NULL, low="#3B4FB8", high="#B71B1A", space="rgb", breaks = NULL, labels = NULL, limits=NULL, trans="identity", legend = TRUE, ..., variable) {
5-
if (is.character(trans)) trans <- Trans$find(trans)
6-
7-
b_and_l <- check_breaks_and_labels(breaks, labels)
8-
9-
.$proto(name=name, low=low, high=high, space=space, .input=variable, .output=variable, .tr = trans, limits=limits, breaks = b_and_l$breaks, .labels = b_and_l$labels, legend = legend, ...)
4+
new <- function(., name = NULL, low = "#3B4FB8", high = "#B71B1A", space = "rgb", ...) {
5+
6+
.super$new(., name = name, low = low, high = high, space = space, ...)
107
}
118

129
map <- function(., x) {
@@ -19,9 +16,6 @@ ScaleGradient <- proto(ScaleContinuous, expr={
1916
nice_ramp(ramp, x)
2017
}
2118

22-
labels <- function(.) {
23-
nulldefault(.$.labels, .$.tr$label(.$input_breaks()))
24-
}
2519
output_breaks <- function(.) {
2620
.$map(.$input_breaks())
2721
}
@@ -93,12 +87,9 @@ ScaleGradient <- proto(ScaleContinuous, expr={
9387
})
9488

9589
ScaleGradient2 <- proto(ScaleContinuous, expr={
96-
new <- function(., name=NULL, low=muted("red"), mid="white", high=muted("blue"), midpoint=0, space="rgb", breaks = NULL, labels = NULL, limits=NULL, trans="identity", legend = TRUE, ..., variable) {
97-
if (is.character(trans)) trans <- Trans$find(trans)
98-
99-
b_and_l <- check_breaks_and_labels(breaks, labels)
100-
101-
.$proto(name=name, low=low, mid=mid, high=high, midpoint=midpoint, space=space, ..., .input=variable, .output=variable, .tr=trans, limits=limits, breaks = b_and_l$breaks, .labels = b_and_l$labels, legend = legend)
90+
new <- function(., name = NULL, low = muted("red"), mid = "white", high = muted("blue"), midpoint = 0, space = "rgb", ...) {
91+
.super$new(., name = name, low = low, mid = mid, high = high,
92+
midpoint = midpoint, space = space, ...)
10293
}
10394

10495
aliases <- c("scale_color_gradient2")
@@ -122,9 +113,6 @@ ScaleGradient2 <- proto(ScaleContinuous, expr={
122113
desc <- "Smooth gradient between three colours (high, low and midpoints)"
123114

124115
output_breaks <- function(.) .$map(.$input_breaks())
125-
labels <- function(.) {
126-
nulldefault(.$.labels, .$.tr$label(.$input_breaks()))
127-
}
128116

129117
icon <- function(.) {
130118
g <- scale_fill_gradient2()
@@ -191,19 +179,12 @@ ScaleGradient2 <- proto(ScaleContinuous, expr={
191179

192180

193181
ScaleGradientn <- proto(ScaleContinuous, expr={
194-
new <- function(., name=NULL, colours, values = NULL, rescale = TRUE, space="rgb", breaks = NULL, labels = NULL, limits = NULL, trans="identity", legend = TRUE, ..., variable) {
195-
if (is.character(trans)) trans <- Trans$find(trans)
196-
if (!is.null(values)) limits <- range(values)
182+
new <- function(., name=NULL, colours, values = NULL, rescale = TRUE, space="rgb", ...) {
197183

198-
b_and_l <- check_breaks_and_labels(breaks, labels)
199-
200-
.$proto(
184+
.super$new(.,
201185
name = name,
202186
colours = colours, values = values, rescale = rescale,
203187
space = space, ...,
204-
.input = variable, .output = variable, .tr = trans,
205-
limits = limits, breaks = b_and_l$breaks, .labels = b_and_l$labels,
206-
legend = legend
207188
)
208189
}
209190

@@ -225,9 +206,6 @@ ScaleGradientn <- proto(ScaleContinuous, expr={
225206
desc <- "Smooth gradient between n colours"
226207

227208
output_breaks <- function(.) .$map(.$input_breaks())
228-
labels <- function(.) {
229-
nulldefault(.$.labels, .$.tr$label(.$input_breaks()))
230-
}
231209

232210
icon <- function(.) {
233211
g <- scale_fill_gradientn(colours = rainbow(7))

0 commit comments

Comments
 (0)