43
43
# ' needs to show the full data range, please use `outlier.shape = NA` instead.
44
44
# ' @param outlier.colour,outlier.color,outlier.fill,outlier.shape,outlier.size,outlier.stroke,outlier.alpha
45
45
# ' Default aesthetics for outliers. Set to `NULL` to inherit from the
46
- # ' aesthetics used for the box.
47
- # '
48
- # ' In the unlikely event you specify both US and UK spellings of colour, the
49
- # ' US spelling will take precedence.
50
- # '
46
+ # ' data's aesthetics.
47
+ # ' @param whisker.colour,whisker.color,whisker.linetype,whisker.linewidth
48
+ # ' Default aesthetics for the whiskers. Set to `NULL` to inherit from the
49
+ # ' data's aesthetics.
50
+ # ' @param median.colour,median.color,median.linetype,median.linewidth
51
+ # ' Default aesthetics for the median line. Set to `NULL` to inherit from the
52
+ # ' data's aesthetics.
53
+ # ' @param staple.colour,staple.color,staple.linetype,staple.linewidth
54
+ # ' Default aesthetics for the staples. Set to `NULL` to inherit from the
55
+ # ' data's aesthetics. Note that staples don't appear unless the `staplewidth`
56
+ # ' argument is set to a non-zero size.
57
+ # ' @param box.colour,box.color,box.linetype,box.linewidth
58
+ # ' Default aesthetics for the boxes. Set to `NULL` to inherit from the
59
+ # ' data's aesthetics.
51
60
# ' @param notch If `FALSE` (default) make a standard box plot. If
52
61
# ' `TRUE`, make a notched box plot. Notches are used to compare groups;
53
62
# ' if the notches of two boxes do not overlap, this suggests that the medians
60
69
# ' `TRUE`, boxes are drawn with widths proportional to the
61
70
# ' square-roots of the number of observations in the groups (possibly
62
71
# ' weighted, using the `weight` aesthetic).
72
+ # ' @note In the unlikely event you specify both US and UK spellings of colour,
73
+ # ' the US spelling will take precedence.
74
+ # '
63
75
# ' @export
64
76
# ' @references McGill, R., Tukey, J. W. and Larsen, W. A. (1978) Variations of
65
77
# ' box plots. The American Statistician 32, 12-16.
@@ -121,6 +133,22 @@ geom_boxplot <- function(mapping = NULL, data = NULL,
121
133
outlier.size = NULL ,
122
134
outlier.stroke = 0.5 ,
123
135
outlier.alpha = NULL ,
136
+ whisker.colour = NULL ,
137
+ whisker.color = NULL ,
138
+ whisker.linetype = NULL ,
139
+ whisker.linewidth = NULL ,
140
+ staple.colour = NULL ,
141
+ staple.color = NULL ,
142
+ staple.linetype = NULL ,
143
+ staple.linewidth = NULL ,
144
+ median.colour = NULL ,
145
+ median.color = NULL ,
146
+ median.linetype = NULL ,
147
+ median.linewidth = NULL ,
148
+ box.colour = NULL ,
149
+ box.color = NULL ,
150
+ box.linetype = NULL ,
151
+ box.linewidth = NULL ,
124
152
notch = FALSE ,
125
153
notchwidth = 0.5 ,
126
154
staplewidth = 0 ,
@@ -140,6 +168,39 @@ geom_boxplot <- function(mapping = NULL, data = NULL,
140
168
}
141
169
}
142
170
171
+ outlier_gp <- list (
172
+ colour = outlier.color %|| % outlier.colour ,
173
+ fill = outlier.fill ,
174
+ shape = outlier.shape ,
175
+ size = outlier.size ,
176
+ stroke = outlier.stroke ,
177
+ alpha = outlier.alpha
178
+ )
179
+
180
+ whisker_gp <- list (
181
+ colour = whisker.color %|| % whisker.colour ,
182
+ linetype = whisker.linetype ,
183
+ linewidth = whisker.linewidth
184
+ )
185
+
186
+ staple_gp <- list (
187
+ colour = staple.color %|| % staple.colour ,
188
+ linetype = staple.linetype ,
189
+ linewidth = staple.linewidth
190
+ )
191
+
192
+ median_gp <- list (
193
+ colour = median.color %|| % median.colour ,
194
+ linetype = median.linetype ,
195
+ linewidth = median.linewidth
196
+ )
197
+
198
+ box_gp <- list (
199
+ colour = box.color %|| % box.colour ,
200
+ linetype = box.linetype ,
201
+ linewidth = box.linewidth
202
+ )
203
+
143
204
check_number_decimal(staplewidth )
144
205
check_bool(outliers )
145
206
@@ -153,12 +214,11 @@ geom_boxplot <- function(mapping = NULL, data = NULL,
153
214
inherit.aes = inherit.aes ,
154
215
params = list2(
155
216
outliers = outliers ,
156
- outlier.colour = outlier.color %|| % outlier.colour ,
157
- outlier.fill = outlier.fill ,
158
- outlier.shape = outlier.shape ,
159
- outlier.size = outlier.size ,
160
- outlier.stroke = outlier.stroke ,
161
- outlier.alpha = outlier.alpha ,
217
+ outlier_gp = outlier_gp ,
218
+ whisker_gp = whisker_gp ,
219
+ staple_gp = staple_gp ,
220
+ median_gp = median_gp ,
221
+ box_gp = box_gp ,
162
222
notch = notch ,
163
223
notchwidth = notchwidth ,
164
224
staplewidth = staplewidth ,
@@ -222,10 +282,9 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
222
282
},
223
283
224
284
draw_group = function (self , data , panel_params , coord , lineend = " butt" ,
225
- linejoin = " mitre" , fatten = 2 , outlier.colour = NULL ,
226
- outlier.fill = NULL , outlier.shape = NULL ,
227
- outlier.size = NULL , outlier.stroke = 0.5 ,
228
- outlier.alpha = NULL , notch = FALSE , notchwidth = 0.5 ,
285
+ linejoin = " mitre" , fatten = 2 , outlier_gp = NULL ,
286
+ whisker_gp = NULL , staple_gp = NULL , median_gp = NULL ,
287
+ box_gp = NULL , notch = FALSE , notchwidth = 0.5 ,
229
288
staplewidth = 0 , varwidth = FALSE , flipped_aes = FALSE ) {
230
289
data <- check_linewidth(data , snake_class(self ))
231
290
data <- flip_data(data , flipped_aes )
@@ -237,50 +296,44 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
237
296
))
238
297
}
239
298
240
- common <- list (
241
- colour = data $ colour ,
242
- linewidth = data $ linewidth ,
243
- linetype = data $ linetype ,
244
- fill = fill_alpha(data $ fill , data $ alpha ),
245
- group = data $ group
246
- )
299
+ common <- list (fill = fill_alpha(data $ fill , data $ alpha ), group = data $ group )
247
300
248
301
whiskers <- data_frame0(
249
302
x = c(data $ x , data $ x ),
250
303
xend = c(data $ x , data $ x ),
251
304
y = c(data $ upper , data $ lower ),
252
305
yend = c(data $ ymax , data $ ymin ),
306
+ colour = rep(whisker_gp $ colour %|| % data $ colour , 2 ),
307
+ linetype = rep(whisker_gp $ linetype %|| % data $ linetype , 2 ),
308
+ linewidth = rep(whisker_gp $ linewidth %|| % data $ linewidth , 2 ),
253
309
alpha = c(NA_real_ , NA_real_ ),
254
310
!!! common ,
255
311
.size = 2
256
312
)
257
313
whiskers <- flip_data(whiskers , flipped_aes )
258
314
259
- box <- data_frame0(
260
- xmin = data $ xmin ,
261
- xmax = data $ xmax ,
262
- ymin = data $ lower ,
263
- y = data $ middle ,
264
- ymax = data $ upper ,
265
- ynotchlower = ifelse(notch , data $ notchlower , NA ),
266
- ynotchupper = ifelse(notch , data $ notchupper , NA ),
267
- notchwidth = notchwidth ,
268
- alpha = data $ alpha ,
269
- !!! common
315
+ box <- transform(
316
+ data ,
317
+ y = middle ,
318
+ ymax = upper ,
319
+ ymin = lower ,
320
+ ynotchlower = ifelse(notch , notchlower , NA ),
321
+ ynotchupper = ifelse(notch , notchupper , NA ),
322
+ notchwidth = notchwidth
270
323
)
271
324
box <- flip_data(box , flipped_aes )
272
325
273
326
if (! is.null(data $ outliers ) && length(data $ outliers [[1 ]]) > = 1 ) {
274
327
outliers <- data_frame0(
275
328
y = data $ outliers [[1 ]],
276
329
x = data $ x [1 ],
277
- colour = outlier. colour %|| % data $ colour [1 ],
278
- fill = outlier. fill %|| % data $ fill [1 ],
279
- shape = outlier. shape %|| % data $ shape [1 ],
280
- size = outlier. size %|| % data $ size [1 ],
281
- stroke = outlier. stroke %|| % data $ stroke [1 ],
330
+ colour = outlier_gp $ colour %|| % data $ colour [1 ],
331
+ fill = outlier_gp $ fill %|| % data $ fill [1 ],
332
+ shape = outlier_gp $ shape %|| % data $ shape [1 ] % || % 19 ,
333
+ size = outlier_gp $ size %|| % data $ size [1 ] % || % 1.5 ,
334
+ stroke = outlier_gp $ stroke %|| % data $ stroke [1 ] % || % 0.5 ,
282
335
fill = NA ,
283
- alpha = outlier. alpha %|| % data $ alpha [1 ],
336
+ alpha = outlier_gp $ alpha %|| % data $ alpha [1 ],
284
337
.size = length(data $ outliers [[1 ]])
285
338
)
286
339
outliers <- flip_data(outliers , flipped_aes )
@@ -296,6 +349,9 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
296
349
xend = rep((data $ xmax - data $ x ) * staplewidth + data $ x , 2 ),
297
350
y = c(data $ ymax , data $ ymin ),
298
351
yend = c(data $ ymax , data $ ymin ),
352
+ linetype = rep(staple_gp $ linetype %|| % data $ linetype , 2 ),
353
+ linewidth = rep(staple_gp $ linewidth %|| % data $ linewidth , 2 ),
354
+ colour = rep(staple_gp $ colour %|| % data $ colour , 2 ),
299
355
alpha = c(NA_real_ , NA_real_ ),
300
356
!!! common ,
301
357
.size = 2
@@ -320,7 +376,9 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
320
376
coord ,
321
377
lineend = lineend ,
322
378
linejoin = linejoin ,
323
- flipped_aes = flipped_aes
379
+ flipped_aes = flipped_aes ,
380
+ middle_gp = median_gp ,
381
+ box_gp = box_gp
324
382
)
325
383
))
326
384
},
0 commit comments