Skip to content

Allow justification of legends larger than the available space #4437

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 4 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ggplot2 (development version)

* Fix a bug in legend justification where justification was lost of the legend
dimensions exceeded the available size (@thomasp85, #3635)

* Fix calculation of confidence interval for locfit smoothing (@topepo, #3806)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be part of the PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I forgot to ask for a news bullet in another PRR I merged and just thought I would fold it in here... If you feel this is too bad we can make a separate commit instead


* Fix bug in `scale_[x|y]_date()` where custom breaks functions that resulted in
fracional dates would get misaligned (@thomasp85, #3965)

Expand Down
25 changes: 20 additions & 5 deletions R/plot-build.r
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,28 @@ ggplot_gtable.ggplot_built <- function(data) {
ypos <- theme$legend.position[2]

# x and y are specified via theme$legend.position (i.e., coords)
legend_box <- editGrob(legend_box,
vp = viewport(x = xpos, y = ypos, just = c(xjust, yjust),
height = legend_height, width = legend_width))
legend_box <- editGrob(
legend_box,
vp = viewport(
x = xpos,
y = ypos,
just = c(xjust, yjust),
height = legend_height,
width = legend_width
)
)
} else {
# x and y are adjusted using justification of legend box (i.e., theme$legend.justification)
legend_box <- editGrob(legend_box,
vp = viewport(x = xjust, y = yjust, just = c(xjust, yjust)))
legend_box <- editGrob(
legend_box,
vp = viewport(
x = xjust,
y = yjust,
just = c(xjust, yjust),
height = legend_height,
width = legend_width
)
)
legend_box <- gtable_add_rows(legend_box, unit(yjust, 'null'))
legend_box <- gtable_add_rows(legend_box, unit(1 - yjust, 'null'), 0)
legend_box <- gtable_add_cols(legend_box, unit(xjust, 'null'), 0)
Expand Down