@@ -115,6 +115,9 @@ GuideAxis <- ggproto(
115
115
116
116
extract_key = function (scale , aesthetic , minor.ticks = FALSE , ... ) {
117
117
major <- Guide $ extract_key(scale , aesthetic , ... )
118
+ if (is.null(major ) && is.null(scale $ scale $ get_breaks())) {
119
+ major <- data_frame0()
120
+ }
118
121
if (! minor.ticks ) {
119
122
return (major )
120
123
}
@@ -147,10 +150,11 @@ GuideAxis <- ggproto(
147
150
extract_decor = function (scale , aesthetic , position , key , cap = " none" , ... ) {
148
151
149
152
value <- c(- Inf , Inf )
150
- if (cap %in% c(" both" , " upper" )) {
153
+ has_key <- ! (is.null(key ) || nrow(key ) < 1 )
154
+ if (cap %in% c(" both" , " upper" ) && has_key ) {
151
155
value [2 ] <- max(key [[aesthetic ]])
152
156
}
153
- if (cap %in% c(" both" , " lower" )) {
157
+ if (cap %in% c(" both" , " lower" ) && has_key ) {
154
158
value [1 ] <- min(key [[aesthetic ]])
155
159
}
156
160
@@ -166,26 +170,32 @@ GuideAxis <- ggproto(
166
170
transform = function (self , params , coord , panel_params ) {
167
171
key <- params $ key
168
172
position <- params $ position
169
-
170
- if (is.null(position ) || nrow(key ) == 0 ) {
171
- return (params )
173
+ check <- FALSE
174
+
175
+ if (! (is.null(position ) || nrow(key ) == 0 )) {
176
+ check <- TRUE
177
+ aesthetics <- names(key )[! grepl(" ^\\ ." , names(key ))]
178
+ if (! all(c(" x" , " y" ) %in% aesthetics )) {
179
+ other_aesthetic <- setdiff(c(" x" , " y" ), aesthetics )
180
+ override_value <- if (position %in% c(" bottom" , " left" )) - Inf else Inf
181
+ key [[other_aesthetic ]] <- override_value
182
+ }
183
+ key <- coord $ transform(key , panel_params )
184
+ params $ key <- key
172
185
}
173
186
174
- aesthetics <- names(key )[! grepl(" ^\\ ." , names(key ))]
175
- if (! all(c(" x" , " y" ) %in% aesthetics )) {
176
- other_aesthetic <- setdiff(c(" x" , " y" ), aesthetics )
177
- override_value <- if (position %in% c(" bottom" , " left" )) - Inf else Inf
178
- key [[other_aesthetic ]] <- override_value
179
- }
180
- key <- coord $ transform(key , panel_params )
181
- params $ key <- key
187
+ if (! is.null(params $ decor )) {
188
+ params $ decor <- coord_munch(coord , params $ decor , panel_params )
182
189
183
- params $ decor <- coord_munch(coord , params $ decor , panel_params )
190
+ if (! coord $ is_linear()) {
191
+ # For non-linear coords, we hardcode the opposite position
192
+ params $ decor $ x <- switch (position , left = 1 , right = 0 , params $ decor $ x )
193
+ params $ decor $ y <- switch (position , top = 0 , bottom = 1 , params $ decor $ y )
194
+ }
195
+ }
184
196
185
- if (! coord $ is_linear()) {
186
- # For non-linear coords, we hardcode the opposite position
187
- params $ decor $ x <- switch (position , left = 1 , right = 0 , params $ decor $ x )
188
- params $ decor $ y <- switch (position , top = 0 , bottom = 1 , params $ decor $ y )
197
+ if (! check ) {
198
+ return (params )
189
199
}
190
200
191
201
# Ported over from `warn_for_position_guide`
0 commit comments