Skip to content

Commit adb4244

Browse files
committed
Don't remove margins for ggmark and cross_mark
1 parent ae0ae16 commit adb4244

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

R/cross-link.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ CrossLink <- ggproto("CrossLink", Cross,
150150
plot$ggalign_link_data <- NULL
151151

152152
# insert the grob
153-
plot + inset(grob, on_top = self$on_top) + theme_recycle()
153+
plot <- plot + inset(grob, on_top = self$on_top)
154+
ggremove_margin(plot, direction) + theme_recycle()
154155
},
155156
summary = function(self, plot) {
156157
header <- ggproto_parent(Cross, self)$summary(plot)

R/ggalign.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ AlignGg <- ggproto("AlignGg", AlignProto,
288288
panel.spacing.x = calc_element("panel.spacing.x", theme)
289289
)
290290
}
291-
plot + theme + theme_recycle()
291+
plot <- plot + theme
292+
ggremove_margin(plot, direction) + theme_recycle()
292293
},
293294
summary = function(self, plot) {
294295
header <- ggproto_parent(AlignProto, self)$summary(plot)

R/ggcross.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ CrossGg <- ggproto("CrossGg", AlignProto,
169169
panel.spacing.x = calc_element("panel.spacing.x", theme)
170170
)
171171
}
172-
plot + theme + theme_recycle()
172+
plot <- plot + theme
173+
ggremove_margin(plot, direction) + theme_recycle()
173174
},
174175
summary = function(self, plot) {
175176
header <- ggproto_parent(AlignProto, self)$summary(plot)

R/ggplot-utils.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ gguse_data <- function(plot, data) {
5050
plot
5151
}
5252

53+
ggremove_margin <- function(plot, direction) {
54+
if (!is.null(direction) && packageVersion("ggplot2") > "3.5.1") {
55+
plot <- plot + switch_direction(
56+
direction,
57+
theme(plot.margin = margin(t = 0, r = NA, b = 0, l = NA)),
58+
theme(plot.margin = margin(t = NA, r = 0, b = NA, l = 0))
59+
)
60+
}
61+
plot
62+
}
63+
5364
######################################################
5465
default_expansion <- function(x = NULL, y = NULL) {
5566
structure(list(x = x, y = y), class = c("ggalign_default_expansion"))

R/layout-stack-composer.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ stack_composer_add.ggalign_plot <- function(plot, composer, design, ...,
119119
# let `align` add other components
120120
plot <- align$build_plot(plot, design = design, ...)
121121
plot <- align$finish_plot(plot, plot_schemes, theme)
122-
if (packageVersion("ggplot2") > "3.5.1") {
123-
plot <- plot + switch_direction(
124-
direction,
125-
theme(plot.margin = margin(t = 0, r = NA, b = 0, l = NA)),
126-
theme(plot.margin = margin(t = NA, r = 0, b = NA, l = 0))
127-
)
128-
}
129122
stack_composer_align_plot(composer, plot, size)
130123
}
131124

R/plot-.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ AlignProto <- ggproto("AlignProto",
121121
plot
122122
},
123123
finish_plot = function(self, plot, schemes, theme) {
124-
plot_add_schemes(plot, schemes) + theme_recycle()
124+
plot <- plot_add_schemes(plot, schemes)
125+
ggremove_margin(plot, self$direction) + theme_recycle()
125126
},
126127

127128
# utils method to print the object, should return a character vector

0 commit comments

Comments
 (0)