@@ -166,7 +166,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
166
166
xlimits <- self $ limits $ r
167
167
ylimits <- self $ limits $ theta
168
168
}
169
- params <- c(
169
+ panel_params <- c(
170
170
view_scales_polar(scale_x , self $ theta , xlimits ,
171
171
expand = params $ expand [c(4 , 2 )]
172
172
),
@@ -177,21 +177,39 @@ CoordRadial <- ggproto("CoordRadial", Coord,
177
177
arc = self $ arc , inner_radius = self $ inner_radius )
178
178
)
179
179
180
- axis_rotation <- self $ r_axis_inside
180
+ panel_params $ r_axis_inside <- self $ r_axis_inside
181
+ if (isFALSE(self $ r_axis_inside )) {
182
+ place <- in_arc(c(0 , 0.5 , 1 , 1.5 ) * pi , self $ arc )
183
+ if (! any(place )) {
184
+ cli :: cli_warn(c(
185
+ " No appropriate placement found for {.arg r_axis_inside}." ,
186
+ i = " Axis will be placed at panel edge."
187
+ ))
188
+ panel_params $ r_axis_inside <- TRUE
189
+ } else {
190
+ panel_params $ r_axis <- if (any(place [c(1 , 3 )])) " left" else " bottom"
191
+ panel_params $ fake_arc <- switch (
192
+ which(place [c(1 , 3 , 2 , 4 )])[1 ],
193
+ c(0 , 2 ), c(1 , 3 ), c(0.5 , 2.5 ), c(1.5 , 3.5 )
194
+ ) * pi
195
+ }
196
+ }
197
+
198
+ axis_rotation <- panel_params $ r_axis_inside
181
199
if (is.numeric(axis_rotation )) {
182
200
theta_scale <- switch (self $ theta , x = scale_x , y = scale_y )
183
201
axis_rotation <- theta_scale $ transform(axis_rotation )
184
- axis_rotation <- oob_squish(axis_rotation , params $ theta.range )
202
+ axis_rotation <- oob_squish(axis_rotation , panel_params $ theta.range )
185
203
axis_rotation <- theta_rescale(
186
- axis_rotation , params $ theta.range ,
187
- params $ arc , 1
204
+ axis_rotation , panel_params $ theta.range ,
205
+ panel_params $ arc , 1
188
206
)
189
- params $ axis_rotation <- rep_len(axis_rotation , length.out = 2 )
207
+ panel_params $ axis_rotation <- rep_len(axis_rotation , length.out = 2 )
190
208
} else {
191
- params $ axis_rotation <- params $ arc
209
+ panel_params $ axis_rotation <- panel_params $ arc
192
210
}
193
211
194
- params
212
+ panel_params
195
213
},
196
214
197
215
setup_panel_guides = function (self , panel_params , guides , params = list ()) {
@@ -229,7 +247,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
229
247
opposite_r <- isTRUE(scales $ r $ position %in% c(" bottom" , " left" ))
230
248
}
231
249
232
- if (! isFALSE(self $ r_axis_inside )) {
250
+ if (! isFALSE(panel_params $ r_axis_inside )) {
233
251
234
252
r_position <- c(" left" , " right" )
235
253
# If both opposite direction and opposite position, don't flip
@@ -244,7 +262,9 @@ CoordRadial <- ggproto("CoordRadial", Coord,
244
262
guide_params [[" r" ]]$ angle <- guide_params [[" r" ]]$ angle %| W | % arc [1 ]
245
263
guide_params [[" r.sec" ]]$ angle <- guide_params [[" r.sec" ]]$ angle %| W | % arc [2 ]
246
264
} else {
247
- r_position <- c(params $ r_axis , opposite_position(params $ r_axis ))
265
+ r_position <- c(panel_params $ r_axis ,
266
+ opposite_position(panel_params $ r_axis )
267
+ )
248
268
if (opposite_r ) {
249
269
r_position <- rev(r_position )
250
270
}
@@ -285,15 +305,15 @@ CoordRadial <- ggproto("CoordRadial", Coord,
285
305
scale = panel_params [t ]
286
306
)
287
307
288
- if (! isFALSE(self $ r_axis_inside )) {
308
+ if (! isFALSE(panel_params $ r_axis_inside )) {
289
309
# For radial axis, we need to pretend that rotation starts at 0 and
290
310
# the bounding box is for circles, otherwise tick positions will be
291
311
# spaced too closely.
292
312
mod <- list (bbox = list (x = c(0 , 1 ), y = c(0 , 1 )), arc = c(0 , 2 * pi ))
293
313
} else {
294
314
# When drawing radial axis outside, we need to pretend that arcs starts
295
315
# at horizontal or vertical position to have the transform work right.
296
- mod <- list (arc = params $ fake_arc )
316
+ mod <- list (arc = panel_params $ fake_arc )
297
317
}
298
318
temp <- modify_list(panel_params , mod )
299
319
@@ -337,14 +357,14 @@ CoordRadial <- ggproto("CoordRadial", Coord,
337
357
},
338
358
339
359
render_axis_v = function (self , panel_params , theme ) {
340
- if (! isFALSE(self $ r_axis_inside )) {
360
+ if (! isFALSE(panel_params $ r_axis_inside )) {
341
361
return (list (left = zeroGrob(), right = zeroGrob()))
342
362
}
343
363
CoordCartesian $ render_axis_v(panel_params , theme )
344
364
},
345
365
346
366
render_axis_h = function (self , panel_params , theme ) {
347
- if (! isFALSE(self $ r_axis_inside )) {
367
+ if (! isFALSE(panel_params $ r_axis_inside )) {
348
368
return (list (top = zeroGrob(), bottom = zeroGrob()))
349
369
}
350
370
CoordCartesian $ render_axis_h(panel_params , theme )
@@ -363,7 +383,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
363
383
364
384
border <- element_render(theme , " panel.border" , fill = NA )
365
385
366
- if (isFALSE(self $ r_axis_inside )) {
386
+ if (isFALSE(panel_params $ r_axis_inside )) {
367
387
out <- grobTree(
368
388
panel_guides_grob(panel_params $ guides , " theta" , theme ),
369
389
panel_guides_grob(panel_params $ guides , " theta.sec" , theme ),
@@ -449,30 +469,6 @@ CoordRadial <- ggproto("CoordRadial", Coord,
449
469
450
470
lapply(scales_x , scale_flip_position )
451
471
lapply(scales_y , scale_flip_position )
452
- },
453
-
454
- setup_params = function (self , data ) {
455
- params <- ggproto_parent(Coord , self )$ setup_params(data )
456
- if (! isFALSE(self $ r_axis_inside )) {
457
- return (params )
458
- }
459
-
460
- place <- in_arc(c(0 , 0.5 , 1 , 1.5 ) * pi , self $ arc )
461
- if (! any(place )) {
462
- cli :: cli_warn(c(
463
- " No appropriate placement found for {.arg r_axis_inside}." ,
464
- i = " Axis will be placed at panel edge."
465
- ))
466
- params $ r_axis_inside <- TRUE
467
- return (params )
468
- }
469
-
470
- params $ r_axis <- if (any(place [c(1 , 3 )])) " left" else " bottom"
471
- params $ fake_arc <- switch (
472
- which(place [c(1 , 3 , 2 , 4 )])[1 ],
473
- c(0 , 2 ), c(1 , 3 ), c(0.5 , 2.5 ), c(1.5 , 3.5 )
474
- ) * pi
475
- params
476
472
}
477
473
)
478
474
0 commit comments