Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggplot2 (development version)

* The plot's title, subtitle and caption now obey horizontal text margins
(#5533).

* Lines where `linewidth = NA` are now dropped in `geom_sf()` (#5204).

* New `guide_axis_logticks()` can be used to draw logarithmic tick marks as
Expand Down
15 changes: 12 additions & 3 deletions R/plot-build.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,24 @@ ggplot_gtable.ggplot_built <- function(data) {
}

# Title
title <- element_render(theme, "plot.title", plot$labels$title, margin_y = TRUE)
title <- element_render(
theme, "plot.title", plot$labels$title,
margin_y = TRUE, margin_x = TRUE
)
title_height <- grobHeight(title)

# Subtitle
subtitle <- element_render(theme, "plot.subtitle", plot$labels$subtitle, margin_y = TRUE)
subtitle <- element_render(
theme, "plot.subtitle", plot$labels$subtitle,
margin_y = TRUE, margin_x = TRUE
)
subtitle_height <- grobHeight(subtitle)

# whole plot annotation
caption <- element_render(theme, "plot.caption", plot$labels$caption, margin_y = TRUE)
caption <- element_render(
theme, "plot.caption", plot$labels$caption,
margin_y = TRUE, margin_x = TRUE
)
caption_height <- grobHeight(caption)

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