Skip to content

Commit 333ae5c

Browse files
authored
Allow justification of legends larger than the available space (#4437)
1 parent 9927d13 commit 333ae5c

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

NEWS.md

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

3+
* Fix a bug in legend justification where justification was lost of the legend
4+
dimensions exceeded the available size (@thomasp85, #3635)
5+
6+
* Fix calculation of confidence interval for locfit smoothing (@topepo, #3806)
7+
38
* Fix bug in `scale_[x|y]_date()` where custom breaks functions that resulted in
49
fracional dates would get misaligned (@thomasp85, #3965)
510

R/plot-build.r

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,28 @@ ggplot_gtable.ggplot_built <- function(data) {
199199
ypos <- theme$legend.position[2]
200200

201201
# x and y are specified via theme$legend.position (i.e., coords)
202-
legend_box <- editGrob(legend_box,
203-
vp = viewport(x = xpos, y = ypos, just = c(xjust, yjust),
204-
height = legend_height, width = legend_width))
202+
legend_box <- editGrob(
203+
legend_box,
204+
vp = viewport(
205+
x = xpos,
206+
y = ypos,
207+
just = c(xjust, yjust),
208+
height = legend_height,
209+
width = legend_width
210+
)
211+
)
205212
} else {
206213
# x and y are adjusted using justification of legend box (i.e., theme$legend.justification)
207-
legend_box <- editGrob(legend_box,
208-
vp = viewport(x = xjust, y = yjust, just = c(xjust, yjust)))
214+
legend_box <- editGrob(
215+
legend_box,
216+
vp = viewport(
217+
x = xjust,
218+
y = yjust,
219+
just = c(xjust, yjust),
220+
height = legend_height,
221+
width = legend_width
222+
)
223+
)
209224
legend_box <- gtable_add_rows(legend_box, unit(yjust, 'null'))
210225
legend_box <- gtable_add_rows(legend_box, unit(1 - yjust, 'null'), 0)
211226
legend_box <- gtable_add_cols(legend_box, unit(xjust, 'null'), 0)

0 commit comments

Comments
 (0)