Skip to content

Commit

Permalink
fix alignment for fake discrete axis
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 6, 2025
1 parent 843d564 commit 0d6b578
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
32 changes: 16 additions & 16 deletions R/layout-align.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,18 @@ ggplot_add.ggalign_design <- function(object, plot, object_name) {
},
# take the tricks to modify scales in place
modify_scales = function(self, scales_x, scales_y) {
if (self$is_linear() || inherits(self, "CoordTrans")) {
# for each scale, we set the `breaks` and `labels`
if (is_discrete_design(x_design)) {
align_discrete_scales(
"x", scales_x, x_design,
.subset2(object, "xlabels")
)
}
if (is_discrete_design(y_design)) {
align_discrete_scales(
"y", scales_y, y_design,
.subset2(object, "ylabels")
)
}
# for each scale, we set the `breaks` and `labels`
if (is_discrete_design(x_design)) {
align_discrete_scales(
"x", scales_x, x_design,
.subset2(object, "xlabels")
)
}
if (is_discrete_design(y_design)) {
align_discrete_scales(
"y", scales_y, y_design,
.subset2(object, "ylabels")
)
}
ggproto_parent(ParentCoord, self)$modify_scales(scales_x, scales_y)
},
Expand All @@ -434,7 +432,8 @@ ggplot_add.ggalign_design <- function(object, plot, object_name) {
self$xlim_list,
recycle_whole(cur_panel, self$n_cycle)
)
if (is_discrete_design(x_design) && scale_x$is_discrete()) {
if (is_discrete_design(x_design) && scale_x$is_discrete() &&
!is.null(scale_x$range$range)) {
# for discrete scale, the limits starts from zero in each
# panel
xlim <- xlim - (min(xlim) - 0.5)
Expand All @@ -446,7 +445,8 @@ ggplot_add.ggalign_design <- function(object, plot, object_name) {
self$ylim_list,
recycle_each(cur_panel, self$n_cycle)
)
if (is_discrete_design(y_design) && scale_y$is_discrete()) {
if (is_discrete_design(y_design) && scale_y$is_discrete() &&
!is.null(scale_x$range$range)) {
# for discrete scale, the limits starts from zero in each
# panel
ylim <- ylim - (min(ylim) - 0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/others.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
Can't convert from `order` <double> to <integer> due to loss of precision.
* Locations: 1

# geom_draw() workds well
# geom_draw2() workds well

Problem while computing aesthetics.
i Error occurred in the 1st layer.
Caused by error in `scale_f()`:
! You must provide draw scale with `scale_draw_manual()`
! You must provide `scale_draw_manual()` to use `geom_draw2()`

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0d6b578

Please sign in to comment.