Skip to content

Commit 1fc1d5e

Browse files
committed
Don't assign into unit vectors to avoid weird grid bug in R 3.2 (and possibly older)
1 parent 14f2360 commit 1fc1d5e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

R/plot-build.r

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,42 +292,42 @@ ggplot_gtable.ggplot_built <- function(data) {
292292
r = ncol(plot_table), clip = "off")
293293
} else {
294294
if (tag_pos == "topleft") {
295-
plot_table$widths[1] <- tag_width
296-
plot_table$heights[1] <- tag_height
295+
plot_table$widths <- unit.c(tag_width, plot_table$widths[-1])
296+
plot_table$heights <- unit.c(tag_height, plot_table$heights[-1])
297297
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
298298
t = 1, l = 1, clip = "off")
299299
} else if (tag_pos == "top") {
300-
plot_table$heights[1] <- tag_height
300+
plot_table$heights <- unit.c(tag_height, plot_table$heights[-1])
301301
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
302302
t = 1, l = 1, r = ncol(plot_table),
303303
clip = "off")
304304
} else if (tag_pos == "topright") {
305-
plot_table$widths[ncol(plot_table)] <- tag_width
306-
plot_table$heights[1] <- tag_height
305+
plot_table$widths <- unit.c(plot_table$widths[-ncol(plot_table)], tag_width)
306+
plot_table$heights <- unit.c(tag_height, plot_table$heights[-1])
307307
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
308308
t = 1, l = ncol(plot_table), clip = "off")
309309
} else if (tag_pos == "left") {
310-
plot_table$widths[1] <- tag_width
310+
plot_table$widths <- unit.c(tag_width, plot_table$widths[-1])
311311
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
312312
t = 1, b = nrow(plot_table), l = 1,
313313
clip = "off")
314314
} else if (tag_pos == "right") {
315-
plot_table$widths[ncol(plot_table)] <- tag_width
315+
plot_table$widths <- unit.c(plot_table$widths[-ncol(plot_table)], tag_width)
316316
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
317317
t = 1, b = nrow(plot_table), l = ncol(plot_table),
318318
clip = "off")
319319
} else if (tag_pos == "bottomleft") {
320-
plot_table$widths[1] <- tag_width
321-
plot_table$heights[nrow(plot_table)] <- tag_height
320+
plot_table$widths <- unit.c(tag_width, plot_table$widths[-1])
321+
plot_table$heights <- unit.c(plot_table$heights[-nrow(plot_table)], tag_height)
322322
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
323323
t = nrow(plot_table), l = 1, clip = "off")
324324
} else if (tag_pos == "bottom") {
325-
plot_table$heights[nrow(plot_table)] <- tag_height
325+
plot_table$heights <- unit.c(plot_table$heights[-nrow(plot_table)], tag_height)
326326
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
327327
t = nrow(plot_table), l = 1, r = ncol(plot_table), clip = "off")
328328
} else if (tag_pos == "bottomright") {
329-
plot_table$widths[ncol(plot_table)] <- tag_width
330-
plot_table$heights[nrow(plot_table)] <- tag_height
329+
plot_table$widths <- unit.c(plot_table$widths[-ncol(plot_table)], tag_width)
330+
plot_table$heights <- unit.c(plot_table$heights[-nrow(plot_table)], tag_height)
331331
plot_table <- gtable_add_grob(plot_table, tag, name = "tag",
332332
t = nrow(plot_table), l = ncol(plot_table), clip = "off")
333333
}

0 commit comments

Comments
 (0)