Skip to content

Commit e8238cf

Browse files
committed
Fix #143
1 parent f551f33 commit e8238cf

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* `shapeGrob()` is now exported for use by other packages (#303)
1313
* Fix a bug in `geom_autohistogram()` that prevented it to be used with
1414
continuous data (#297)
15+
* `facet_zoom()` now throws a better error when used with `coord_flip()` (#143)
1516

1617
# ggforce 0.4.1
1718

R/facet_zoom.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ FacetZoom <- ggproto('FacetZoom', Facet,
157157
x_vars <- intersect(x_scales[[1]]$aesthetics, names(layer_data))
158158
SCALE_X <- layout$SCALE_X[match_id]
159159

160-
if (!is.null(params$xlim)) {
160+
if (!is.null(params$xlim) && length(x_scales) > 1) {
161161
x_scales[[2]]$train(x_scales[[2]]$transform(params$xlim))
162162
scale_apply(layer_data, x_vars, 'train', SCALE_X, x_scales[-2])
163163
} else {
@@ -172,7 +172,7 @@ FacetZoom <- ggproto('FacetZoom', Facet,
172172
y_vars <- intersect(y_scales[[1]]$aesthetics, names(layer_data))
173173
SCALE_Y <- layout$SCALE_Y[match_id]
174174

175-
if (!is.null(params$ylim)) {
175+
if (!is.null(params$ylim) && length(y_scales) > 1) {
176176
y_scales[[2]]$train(y_scales[[2]]$transform(params$ylim))
177177
scale_apply(layer_data, y_vars, 'train', SCALE_Y, y_scales[-2])
178178
} else {
@@ -358,7 +358,7 @@ FacetZoom <- ggproto('FacetZoom', Facet,
358358
zoom_y <- calc_element('zoom.y', theme)
359359

360360
if (!(is.null(params$x) && is.null(params$xlim)) &&
361-
params$show.area && !inherits(zoom_x, 'element_blank')) {
361+
params$show.area && !inherits(zoom_x, 'element_blank') && length(x_scales) > 1) {
362362
zoom_prop <- rescale(x_scales[[2]]$dimension(expansion(x_scales[[2]])),
363363
from = x_scales[[1]]$dimension(expansion(x_scales[[1]]))
364364
)
@@ -377,7 +377,7 @@ FacetZoom <- ggproto('FacetZoom', Facet,
377377
x_back <- zeroGrob()
378378
}
379379
if (!(is.null(params$y) && is.null(params$ylim)) &&
380-
params$show.area && !inherits(zoom_y, 'element_blank')) {
380+
params$show.area && !inherits(zoom_y, 'element_blank') && length(y_scales) > 1) {
381381
zoom_prop <- rescale(y_scales[[2]]$dimension(expansion(y_scales[[2]])),
382382
from = y_scales[[1]]$dimension(expansion(y_scales[[1]]))
383383
)

0 commit comments

Comments
 (0)