@@ -105,10 +105,11 @@ CoordPolar <- ggproto("CoordPolar", Coord,
105
105
},
106
106
107
107
setup_panel_params = function (self , scale_x , scale_y , params = list ()) {
108
- scales <- list ( x = scale_x , y = scale_y )
108
+
109
109
ret <- list (x = list (), y = list ())
110
110
for (n in c(" x" , " y" )) {
111
- scale <- scales [[n ]]
111
+
112
+ scale <- get(paste0(" scale_" , n ))
112
113
limits <- self $ limits [[n ]]
113
114
114
115
if (self $ theta == n ) {
@@ -119,10 +120,6 @@ CoordPolar <- ggproto("CoordPolar", Coord,
119
120
range <- expand_limits_scale(scale , expansion , coord_limits = limits )
120
121
121
122
out <- scale $ break_info(range )
122
-
123
- ret [[n ]]$ primary_axis <- view_scale_primary(scale , scale $ get_limits(), out $ range )
124
- ret [[n ]]$ secondary_axis <- view_scale_secondary(scale , scale $ get_limits(), out $ range )
125
-
126
123
ret [[n ]]$ range <- out $ range
127
124
ret [[n ]]$ major <- out $ major_source
128
125
ret [[n ]]$ minor <- out $ minor_source
@@ -133,11 +130,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
133
130
ret [[n ]]$ sec.labels <- out $ sec.labels
134
131
}
135
132
136
- details <- list (
137
- x = ret $ x $ primary_axis ,
138
- y = ret $ y $ primary_axis ,
139
- x.sec = ret $ x $ secondary_axis ,
140
- y.sec = ret $ y $ secondary_axis ,
133
+ details = list (
141
134
x.range = ret $ x $ range , y.range = ret $ y $ range ,
142
135
x.major = ret $ x $ major , y.major = ret $ y $ major ,
143
136
x.minor = ret $ x $ minor , y.minor = ret $ y $ minor ,
@@ -149,80 +142,18 @@ CoordPolar <- ggproto("CoordPolar", Coord,
149
142
)
150
143
151
144
if (self $ theta == " y" ) {
152
- # replace x to r, and x.foo to r.foo
153
- names(details ) <- gsub(" x(\\ .|$)" , " r\\ 1" , names(details ))
154
- names(details ) <- gsub(" y(\\ .|$)" , " theta\\ 1" , names(details ))
145
+ names(details ) <- gsub(" x\\ ." , " r." , names(details ))
146
+ names(details ) <- gsub(" y\\ ." , " theta." , names(details ))
155
147
details $ r.arrange <- scale_x $ axis_order()
156
148
} else {
157
- names(details ) <- gsub(" x( \\ .|$) " , " theta\\ 1 " , names(details ))
158
- names(details ) <- gsub(" y( \\ .|$) " , " r\\ 1 " , names(details ))
149
+ names(details ) <- gsub(" x\\ ." , " theta. " , names(details ))
150
+ names(details ) <- gsub(" y\\ ." , " r. " , names(details ))
159
151
details $ r.arrange <- scale_y $ axis_order()
160
152
}
161
153
162
154
details
163
155
},
164
156
165
- # TODO: it's not very nice to copy the whole method just to tweak the
166
- # `aesthetics` for r and theta
167
- setup_panel_guides = function (self , panel_params , guides , params = list ()) {
168
- aesthetics <- c(" r" , " theta" , " r.sec" , " theta.sec" )
169
- names(aesthetics ) <- aesthetics
170
-
171
- # If the panel_params doesn't contain the scale, do not use a guide for that aesthetic
172
- idx <- vapply(aesthetics , function (aesthetic ) {
173
- scale <- panel_params [[aesthetic ]]
174
- ! is.null(scale ) && inherits(scale , " ViewScale" )
175
- }, logical (1L ))
176
- aesthetics <- aesthetics [idx ]
177
-
178
- # resolve the specified guide from the scale and/or guides
179
- guides <- lapply(aesthetics , function (aesthetic ) {
180
- resolve_guide(
181
- aesthetic ,
182
- panel_params [[aesthetic ]],
183
- guides ,
184
- default = guide_axis(),
185
- null = guide_none()
186
- )
187
- })
188
-
189
- # resolve the guide definition as a "guide" S3
190
- guides <- lapply(guides , validate_guide )
191
-
192
- # if there is an "position" specification in the scale, pass this on to the guide
193
- # ideally, this should be specified in the guide
194
- guides <- lapply(aesthetics , function (aesthetic ) {
195
- guide <- guides [[aesthetic ]]
196
- scale <- panel_params [[aesthetic ]]
197
- # position could be NULL here for an empty scale
198
- guide $ position <- guide $ position %| W | % scale $ position
199
- guide
200
- })
201
-
202
- panel_params $ guides <- guides
203
- panel_params
204
- },
205
-
206
- # TODO: it's not very nice to copy the whole method just to tweak the
207
- # `aesthetics` for r and theta
208
- train_panel_guides = function (self , panel_params , layers , default_mapping , params = list ()) {
209
- aesthetics <- c(" r" , " theta" , " r.sec" , " theta.sec" )
210
- names(aesthetics ) <- aesthetics
211
- # If the panel_params doesn't contain the scale, there's no guide for the aesthetic
212
- aesthetics <- intersect(aesthetics , names(panel_params $ guides ))
213
-
214
- panel_params $ guides <- lapply(aesthetics , function (aesthetic ) {
215
- axis <- strsplit(aesthetic , " ." , fixed = TRUE )[[1 ]][1 ]
216
- guide <- panel_params $ guides [[aesthetic ]]
217
- guide <- guide_train(guide , panel_params [[aesthetic ]])
218
- guide <- guide_transform(guide , self , panel_params )
219
- guide <- guide_geom(guide , layers , default_mapping )
220
- guide
221
- })
222
-
223
- panel_params
224
- },
225
-
226
157
transform = function (self , data , panel_params ) {
227
158
data <- rename_data(self , data )
228
159
@@ -281,23 +212,23 @@ CoordPolar <- ggproto("CoordPolar", Coord,
281
212
element_render(theme , " panel.background" ),
282
213
if (length(theta ) > 0 ) element_render(
283
214
theme , majortheta , name = " angle" ,
284
- x = c(rbind( 0 , 0.45 * sin(theta ) )) + 0.5 ,
285
- y = c(rbind( 0 , 0.45 * cos(theta ) )) + 0.5 ,
215
+ x = vec_interleave( 0 , 0.45 * sin(theta )) + 0.5 ,
216
+ y = vec_interleave( 0 , 0.45 * cos(theta )) + 0.5 ,
286
217
id.lengths = rep(2 , length(theta )),
287
218
default.units = " native"
288
219
),
289
220
if (length(thetamin ) > 0 ) element_render(
290
221
theme , minortheta , name = " angle" ,
291
- x = c(rbind( 0 , 0.45 * sin(thetamin ) )) + 0.5 ,
292
- y = c(rbind( 0 , 0.45 * cos(thetamin ) )) + 0.5 ,
222
+ x = vec_interleave( 0 , 0.45 * sin(thetamin )) + 0.5 ,
223
+ y = vec_interleave( 0 , 0.45 * cos(thetamin )) + 0.5 ,
293
224
id.lengths = rep(2 , length(thetamin )),
294
225
default.units = " native"
295
226
),
296
227
297
228
element_render(
298
229
theme , majorr , name = " radius" ,
299
- x = rep(rfine , each = length(thetafine )) * sin(thetafine ) + 0.5 ,
300
- y = rep(rfine , each = length(thetafine )) * cos(thetafine ) + 0.5 ,
230
+ x = rep(rfine , each = length(thetafine )) * rep( sin(thetafine ), length( rfine ) ) + 0.5 ,
231
+ y = rep(rfine , each = length(thetafine )) * rep( cos(thetafine ), length( rfine ) ) + 0.5 ,
301
232
id.lengths = rep(length(thetafine ), length(rfine )),
302
233
default.units = " native"
303
234
)
@@ -375,6 +306,14 @@ CoordPolar <- ggproto("CoordPolar", Coord,
375
306
)
376
307
},
377
308
309
+ labels = function (self , labels , panel_params ) {
310
+ if (self $ theta == " y" ) {
311
+ list (x = labels $ y , y = labels $ x )
312
+ } else {
313
+ labels
314
+ }
315
+ },
316
+
378
317
modify_scales = function (self , scales_x , scales_y ) {
379
318
if (self $ theta != " y" )
380
319
return ()
0 commit comments