Skip to content

Commit 15bde2f

Browse files
authored
Enable horizontal margins on (sub)title/caption (#5545)
* enable x-margins * add news bullet
1 parent 5c7867d commit 15bde2f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 (development version)
22

3+
* The plot's title, subtitle and caption now obey horizontal text margins
4+
(#5533).
5+
36
* New `guide_axis_stack()` to combine other axis guides on top of one another.
47

58
* New `guide_custom()` function for drawing custom graphical objects (grobs)

R/plot-build.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,24 @@ ggplot_gtable.ggplot_built <- function(data) {
265265
}
266266

267267
# Title
268-
title <- element_render(theme, "plot.title", plot$labels$title, margin_y = TRUE)
268+
title <- element_render(
269+
theme, "plot.title", plot$labels$title,
270+
margin_y = TRUE, margin_x = TRUE
271+
)
269272
title_height <- grobHeight(title)
270273

271274
# Subtitle
272-
subtitle <- element_render(theme, "plot.subtitle", plot$labels$subtitle, margin_y = TRUE)
275+
subtitle <- element_render(
276+
theme, "plot.subtitle", plot$labels$subtitle,
277+
margin_y = TRUE, margin_x = TRUE
278+
)
273279
subtitle_height <- grobHeight(subtitle)
274280

275281
# whole plot annotation
276-
caption <- element_render(theme, "plot.caption", plot$labels$caption, margin_y = TRUE)
282+
caption <- element_render(
283+
theme, "plot.caption", plot$labels$caption,
284+
margin_y = TRUE, margin_x = TRUE
285+
)
277286
caption_height <- grobHeight(caption)
278287

279288
# positioning of title and subtitle is governed by plot.title.position

0 commit comments

Comments
 (0)