Skip to content

Commit 487d7eb

Browse files
committed
let plot spacer always be the one of the last added
1 parent ad5ef6d commit 487d7eb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

R/layout-circle-build.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ circle_build <- function(circle, schemes = NULL, theme = NULL) {
5858
# For each plot, the plot size is calculated by adding the space for the
5959
# inner radius of each track.
6060
index <- seq_along(plot_list)
61-
if (identical(circle@direction, "outward")) {
61+
direction <- circle@direction
62+
if (identical(direction, "outward")) {
6263
plot_sizes <- radial$inner_radius[1L] / 0.4 + cumsum(plot_track)
6364
} else {
6465
plot_sizes <- 1 - cumsum(c(0, plot_track[-length(plot_track)]))
@@ -132,6 +133,7 @@ circle_build <- function(circle, schemes = NULL, theme = NULL) {
132133
scales::rescale(0.5, from = bbox$x),
133134
scales::rescale(0.5, from = bbox$y)
134135
)
136+
spacing <- calc_element("panel.spacing.r", plot_theme)
135137

136138
if (is.null(plot_table)) {
137139
plot_table <- gt
@@ -140,14 +142,17 @@ circle_build <- function(circle, schemes = NULL, theme = NULL) {
140142
rescale_factor <- last_plot_size / plot_size
141143

142144
# the spacer between two plots
143-
spacing <- calc_element("panel.spacing.r", plot_theme)
144-
if (inherits(spacing, "element_blank") || is.null(spacing)) {
145-
spacing <- unit(0, "mm")
145+
if (identical(direction, "outward")) {
146+
spacer <- last_spacing
147+
} else {
148+
spacer <- spacing
149+
}
150+
if (inherits(spacer, "element_blank") || is.null(spacer)) {
151+
spacer <- unit(0, "mm")
146152
}
147-
148153
plot_table <- editGrob(plot_table, vp = viewport(
149-
width = unit(rescale_factor, "npc") - spacing,
150-
height = unit(rescale_factor, "npc") - spacing,
154+
width = unit(rescale_factor, "npc") - spacer,
155+
height = unit(rescale_factor, "npc") - spacer,
151156
x = origin[1L], y = origin[2L], just = just,
152157
default.units = "native", clip = "off"
153158
))
@@ -186,6 +191,7 @@ circle_build <- function(circle, schemes = NULL, theme = NULL) {
186191
}
187192
origin <- just
188193
last_plot_size <- plot_size # the last plot panel size
194+
last_spacing <- spacing
189195
}
190196
# attach the guide legends
191197
guides <- lapply(c(.TLBR, "inside"), function(guide_pos) {

0 commit comments

Comments
 (0)