22
22
# ' scale, or with `breaks` if provided. If this is a named vector, then the
23
23
# ' values will be matched based on the names instead. Data values that don't
24
24
# ' match will be given `na.value`.
25
+ # ' @param breaks One of:
26
+ # ' - `NULL` for no breaks
27
+ # ' - `waiver()` for the default breaks (the scale limits)
28
+ # ' - A character vector of breaks
29
+ # ' - A function that takes the limits as input and returns breaks
30
+ # ' as output
25
31
# ' @section Color Blindness:
26
32
# ' Many color palettes derived from RGB combinations (like the "rainbow" color
27
33
# ' palette) are not suitable to support all viewers, especially those with
74
80
75
81
# ' @rdname scale_manual
76
82
# ' @export
77
- scale_colour_manual <- function (... , values , aesthetics = " colour" ) {
78
- manual_scale(aesthetics , values , ... )
83
+ scale_colour_manual <- function (... , values , aesthetics = " colour" , breaks = waiver() ) {
84
+ manual_scale(aesthetics , values , breaks , ... )
79
85
}
80
86
81
87
# ' @rdname scale_manual
82
88
# ' @export
83
- scale_fill_manual <- function (... , values , aesthetics = " fill" ) {
84
- manual_scale(aesthetics , values , ... )
89
+ scale_fill_manual <- function (... , values , aesthetics = " fill" , breaks = waiver() ) {
90
+ manual_scale(aesthetics , values , breaks , ... )
85
91
}
86
92
87
93
# ' @rdname scale_manual
88
94
# ' @export
89
- scale_size_manual <- function (... , values ) {
90
- manual_scale(" size" , values , ... )
95
+ scale_size_manual <- function (... , values , breaks = waiver() ) {
96
+ manual_scale(" size" , values , breaks , ... )
91
97
}
92
98
93
99
# ' @rdname scale_manual
94
100
# ' @export
95
- scale_shape_manual <- function (... , values ) {
96
- manual_scale(" shape" , values , ... )
101
+ scale_shape_manual <- function (... , values , breaks = waiver() ) {
102
+ manual_scale(" shape" , values , breaks , ... )
97
103
}
98
104
99
105
# ' @rdname scale_manual
100
106
# ' @export
101
- scale_linetype_manual <- function (... , values ) {
102
- manual_scale(" linetype" , values , ... )
107
+ scale_linetype_manual <- function (... , values , breaks = waiver() ) {
108
+ manual_scale(" linetype" , values , breaks , ... )
103
109
}
104
110
105
111
# ' @rdname scale_manual
106
112
# ' @export
107
- scale_alpha_manual <- function (... , values ) {
108
- manual_scale(" alpha" , values , ... )
113
+ scale_alpha_manual <- function (... , values , breaks = waiver() ) {
114
+ manual_scale(" alpha" , values , breaks , ... )
109
115
}
110
116
111
117
# ' @rdname scale_manual
112
118
# ' @export
113
- scale_discrete_manual <- function (aesthetics , ... , values ) {
114
- manual_scale(aesthetics , values , ... )
119
+ scale_discrete_manual <- function (aesthetics , ... , values , breaks = waiver() ) {
120
+ manual_scale(aesthetics , values , breaks , ... )
115
121
}
116
122
117
123
118
- manual_scale <- function (aesthetic , values = NULL , ... ) {
124
+ manual_scale <- function (aesthetic , values = NULL , breaks = waiver(), ... ) {
119
125
# check for missing `values` parameter, in lieu of providing
120
126
# a default to all the different scale_*_manual() functions
121
127
if (is_missing(values )) {
@@ -125,15 +131,14 @@ manual_scale <- function(aesthetic, values = NULL, ...) {
125
131
}
126
132
127
133
# order values according to breaks
128
- args <- list (... )
129
- if (is.vector(values ) && is.null(names(values ))
130
- && " breaks" %in% names(args )) {
131
- if (length(args [[" breaks" ]]) != length(values )) {
134
+ if (is.vector(values ) && is.null(names(values )) && ! is.waive(breaks ) &&
135
+ ! is.null(breaks )) {
136
+ if (length(breaks ) != length(values )) {
132
137
stop(" Differing number of values and breaks in manual scale. " ,
133
- length(values ), " values provided compared to " ,
134
- length( args [[ " breaks " ]]), " breaks." , call. = FALSE )
138
+ length(values ), " values provided compared to " , length( breaks ),
139
+ " breaks." , call. = FALSE )
135
140
}
136
- names(values ) <- args [[ " breaks" ]]
141
+ names(values ) <- breaks
137
142
}
138
143
139
144
pal <- function (n ) {
@@ -143,5 +148,5 @@ manual_scale <- function(aesthetic, values = NULL, ...) {
143
148
}
144
149
values
145
150
}
146
- discrete_scale(aesthetic , " manual" , pal , ... )
151
+ discrete_scale(aesthetic , " manual" , pal , breaks = breaks , ... )
147
152
}
0 commit comments