@@ -78,95 +78,6 @@ scale_fill_hue <- function(name = waiver(), ..., h = c(0, 360) + 15, c = 100,
78
78
)
79
79
}
80
80
81
-
82
- # ' Discrete colour scales
83
- # '
84
- # ' The default discrete colour scale. Defaults to [scale_fill_hue()]/[scale_fill_brewer()]
85
- # ' unless `type` (which defaults to the `ggplot2.discrete.fill`/`ggplot2.discrete.colour` options)
86
- # ' is specified.
87
- # '
88
- # ' @param ... Additional parameters passed on to the scale type,
89
- # ' @inheritParams discrete_scale
90
- # ' @param type One of the following:
91
- # ' * A character vector of color codes. The codes are used for a 'manual' color
92
- # ' scale as long as the number of codes exceeds the number of data levels
93
- # ' (if there are more levels than codes, [scale_colour_hue()]/[scale_fill_hue()]
94
- # ' are used to construct the default scale). If this is a named vector, then the color values
95
- # ' will be matched to levels based on the names of the vectors. Data values that
96
- # ' don't match will be set as `na.value`.
97
- # ' * A list of character vectors of color codes. The minimum length vector that exceeds the
98
- # ' number of data levels is chosen for the color scaling. This is useful if you
99
- # ' want to change the color palette based on the number of levels.
100
- # ' * A function that returns a discrete colour/fill scale (e.g., [scale_fill_hue()],
101
- # ' [scale_fill_brewer()], etc).
102
- # ' @export
103
- # ' @seealso
104
- # ' The `r link_book("discrete colour scales section", "scales-colour#sec-colour-discrete")`
105
- # ' @examples
106
- # ' # Template function for creating densities grouped by a variable
107
- # ' cty_by_var <- function(var) {
108
- # ' ggplot(mpg, aes(cty, colour = factor({{var}}), fill = factor({{var}}))) +
109
- # ' geom_density(alpha = 0.2)
110
- # ' }
111
- # '
112
- # ' # The default, scale_fill_hue(), is not colour-blind safe
113
- # ' cty_by_var(class)
114
- # '
115
- # ' # (Temporarily) set the default to Okabe-Ito (which is colour-blind safe)
116
- # ' okabe <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
117
- # ' withr::with_options(
118
- # ' list(ggplot2.discrete.fill = okabe),
119
- # ' print(cty_by_var(class))
120
- # ' )
121
- # '
122
- # ' # Define a collection of palettes to alter the default based on number of levels to encode
123
- # ' discrete_palettes <- list(
124
- # ' c("skyblue", "orange"),
125
- # ' RColorBrewer::brewer.pal(3, "Set2"),
126
- # ' RColorBrewer::brewer.pal(6, "Accent")
127
- # ' )
128
- # ' withr::with_options(
129
- # ' list(ggplot2.discrete.fill = discrete_palettes), {
130
- # ' # 1st palette is used when there 1-2 levels (e.g., year)
131
- # ' print(cty_by_var(year))
132
- # ' # 2nd palette is used when there are 3 levels
133
- # ' print(cty_by_var(drv))
134
- # ' # 3rd palette is used when there are 4-6 levels
135
- # ' print(cty_by_var(fl))
136
- # ' })
137
- # '
138
- scale_colour_discrete <- function (... , aesthetics = " colour" , na.value = " grey50" ,
139
- type = getOption(" ggplot2.discrete.colour" )) {
140
- if (! is.null(type )) {
141
- scale <- scale_backward_compatibility(
142
- ... , na.value = na.value , scale = type ,
143
- aesthetic = " colour" , type = " discrete"
144
- )
145
- return (scale )
146
- }
147
- discrete_scale(
148
- aesthetics , palette = NULL , na.value = na.value ,
149
- ...
150
- )
151
- }
152
-
153
- # ' @rdname scale_colour_discrete
154
- # ' @export
155
- scale_fill_discrete <- function (... , aesthetics = " fill" , na.value = " grey50" ,
156
- type = getOption(" ggplot2.discrete.fill" )) {
157
- if (! is.null(type )) {
158
- scale <- scale_backward_compatibility(
159
- ... , na.value = na.value , scale = type ,
160
- aesthetic = " fill" , type = " discrete"
161
- )
162
- return (scale )
163
- }
164
- discrete_scale(
165
- aesthetics , palette = NULL , na.value = na.value ,
166
- ...
167
- )
168
- }
169
-
170
81
scale_colour_qualitative <- function (name = waiver(), ... , type = NULL ,
171
82
h = c(0 , 360 ) + 15 , c = 100 , l = 65 ,
172
83
h.start = 0 , direction = 1 ,
0 commit comments