Skip to content

Axis alignment over multiple panels #5826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ GuideAxis <- ggproto(
# Unlist the 'label' grobs
z <- if (params$position == "left") c(2, 1, 3) else 1:3
z <- rep(z, c(1, length(grobs$labels), 1))
has_labels <- !is.zero(grobs$labels[[1]])
grobs <- c(list(grobs$ticks), grobs$labels, list(grobs$title))

# Initialise empty gtable
Expand All @@ -430,10 +431,25 @@ GuideAxis <- ggproto(
vp <- exec(
viewport,
!!params$orth_aes := unit(params$orth_side, "npc"),
!!params$orth_size := params$measure_gtable(gt),
!!params$orth_size := max(params$measure_gtable(gt), unit(1, "npc")),
just = params$opposite
)

# Add null-unit padding to justify based on eventual gtable cell shape
# rather than dimensions of this axis alone.
if (has_labels && params$position %in% c("left", "right")) {
where <- layout$l[-c(1, length(layout$l))]
just <- with(elements$text, rotate_just(angle, hjust, vjust))$hjust %||% 0.5
gt <- gtable_add_cols(gt, unit(just, "null"), pos = min(where) - 1)
gt <- gtable_add_cols(gt, unit(1 - just, "null"), pos = max(where) + 1)
}
if (has_labels && params$position %in% c("top", "bottom")) {
where <- layout$t[-c(1, length(layout$t))]
just <- with(elements$text, rotate_just(angle, hjust, vjust))$vjust %||% 0.5
gt <- gtable_add_rows(gt, unit(1 - just, "null"), pos = min(where) - 1)
gt <- gtable_add_rows(gt, unit(just, "null"), pos = max(where) + 1)
}

# Assemble with axis line
absoluteGrob(
gList(axis_line, gt),
Expand Down