@@ -125,8 +125,18 @@ CoordTrans <- ggproto("CoordTrans", Coord,
125
125
},
126
126
127
127
transform = function (self , data , panel_params ) {
128
- trans_x <- function (data ) transform_value(self $ trans $ x , data , panel_params $ x.range )
129
- trans_y <- function (data ) transform_value(self $ trans $ y , data , panel_params $ y.range )
128
+ # trans_x() and trans_y() needs to keep Inf values because this can be called
129
+ # in guide_transform.axis()
130
+ trans_x <- function (data ) {
131
+ idx <- ! is.infinite(data )
132
+ data [idx ] <- transform_value(self $ trans $ x , data [idx ], panel_params $ x.range )
133
+ data
134
+ }
135
+ trans_y <- function (data ) {
136
+ idx <- ! is.infinite(data )
137
+ data [idx ] <- transform_value(self $ trans $ y , data [idx ], panel_params $ y.range )
138
+ data
139
+ }
130
140
131
141
new_data <- transform_position(data , trans_x , trans_y )
132
142
@@ -138,8 +148,8 @@ CoordTrans <- ggproto("CoordTrans", Coord,
138
148
139
149
setup_panel_params = function (self , scale_x , scale_y , params = list ()) {
140
150
c(
141
- train_trans (scale_x , self $ limits $ x , self $ trans $ x , " x " , self $ expand ),
142
- train_trans (scale_y , self $ limits $ y , self $ trans $ y , " y " , self $ expand )
151
+ view_scales_from_scale_with_coord_trans (scale_x , self $ limits $ x , self $ trans $ x , self $ expand ),
152
+ view_scales_from_scale_with_coord_trans (scale_y , self $ limits $ y , self $ trans $ y , self $ expand )
143
153
)
144
154
},
145
155
@@ -154,20 +164,16 @@ CoordTrans <- ggproto("CoordTrans", Coord,
154
164
},
155
165
156
166
render_axis_h = function (panel_params , theme ) {
157
- arrange <- panel_params $ x.arrange %|| % c(" secondary" , " primary" )
158
-
159
167
list (
160
- top = render_axis (panel_params , arrange [ 1 ], " x " , " top" , theme ),
161
- bottom = render_axis (panel_params , arrange [ 2 ], " x " , " bottom" , theme )
168
+ top = panel_guides_grob (panel_params $ guides , position = " top" , theme = theme ),
169
+ bottom = panel_guides_grob (panel_params $ guides , position = " bottom" , theme = theme )
162
170
)
163
171
},
164
172
165
173
render_axis_v = function (panel_params , theme ) {
166
- arrange <- panel_params $ y.arrange %|| % c(" primary" , " secondary" )
167
-
168
174
list (
169
- left = render_axis (panel_params , arrange [ 1 ], " y " , " left" , theme ),
170
- right = render_axis (panel_params , arrange [ 2 ], " y " , " right" , theme )
175
+ left = panel_guides_grob (panel_params $ guides , position = " left" , theme = theme ),
176
+ right = panel_guides_grob (panel_params $ guides , position = " right" , theme = theme )
171
177
)
172
178
}
173
179
)
@@ -178,14 +184,16 @@ transform_value <- function(trans, value, range) {
178
184
rescale(trans $ transform(value ), 0 : 1 , range )
179
185
}
180
186
181
- train_trans <- function (scale , coord_limits , trans , name , expand = TRUE ) {
187
+ # TODO: can we merge this with view_scales_from_scale()?
188
+ view_scales_from_scale_with_coord_trans <- function (scale , coord_limits , trans , expand = TRUE ) {
182
189
expansion <- default_expansion(scale , expand = expand )
183
190
scale_trans <- scale $ trans %|| % identity_trans()
184
191
coord_limits <- coord_limits %|| % scale_trans $ inverse(c(NA , NA ))
192
+ scale_limits <- scale $ get_limits()
185
193
186
194
if (scale $ is_discrete()) {
187
195
continuous_ranges <- expand_limits_discrete_trans(
188
- scale $ get_limits() ,
196
+ scale_limits ,
189
197
expansion ,
190
198
coord_limits ,
191
199
trans ,
@@ -195,7 +203,7 @@ train_trans <- function(scale, coord_limits, trans, name, expand = TRUE) {
195
203
# transform user-specified limits to scale transformed space
196
204
coord_limits <- scale $ trans $ transform(coord_limits )
197
205
continuous_ranges <- expand_limits_continuous_trans(
198
- scale $ get_limits() ,
206
+ scale_limits ,
199
207
expansion ,
200
208
coord_limits ,
201
209
trans
@@ -216,6 +224,10 @@ train_trans <- function(scale, coord_limits, trans, name, expand = TRUE) {
216
224
out $ sec.minor_source <- transform_value(trans , out $ sec.minor_source , out $ range )
217
225
218
226
out <- list (
227
+ # Note that a ViewScale requires a limit and a range that are before the
228
+ # Coord's transformation, so we pass `continuous_range`, not `continuous_range_coord`.
229
+ view_scale_primary(scale , scale_limits , continuous_ranges $ continuous_range ),
230
+ sec = view_scale_secondary(scale , scale_limits , continuous_ranges $ continuous_range ),
219
231
range = out $ range ,
220
232
labels = out $ labels ,
221
233
major = out $ major_source ,
@@ -224,7 +236,9 @@ train_trans <- function(scale, coord_limits, trans, name, expand = TRUE) {
224
236
sec.major = out $ sec.major_source ,
225
237
sec.minor = out $ sec.minor_source
226
238
)
227
- names(out ) <- paste(name , names(out ), sep = " ." )
239
+
240
+ aesthetic <- scale $ aesthetics [1 ]
241
+ names(out ) <- c(aesthetic , paste(aesthetic , names(out )[- 1 ], sep = " ." ))
228
242
out
229
243
}
230
244
0 commit comments