为嵌套图隐藏的调整标签
Adjusted labels hidden for nested plots
如何使嵌套 plot_grid 图中的调整标签不隐藏在其他图下方?
这很好用:
# label 'b' is visible on top of figure a
plot_grid(ggdraw(), ggdraw(), nrow=2, labels=c("a", "b"), hjust=c(-0.5, -5), vjust=c(1,-2))
但不是这个:
# label 'b' is invisible below figure a.
plot_grid(ggdraw(),
plot_grid(ggdraw(), ggdraw(),
nrow=2, rel_heights = c(0.4, 0.6), labels=c("b", "c"), hjust=c(-5,-0.5), vjust=c(0.5,0)),
nrow=2, rel_heights = c(0.33, 0.66))
这是一个剪辑问题。 plot_grid()
使用 ggplot 绘制网格,ggplot 会裁剪掉绘图面板之外的内容。您的截止字母部分落在绘图面板之外:
p1 <- ggdraw() + theme(plot.background = element_rect(fill = "#FF000080", color = NA))
p2 <- ggdraw() + theme(plot.background = element_rect(fill = "#00FF0080", color = NA))
p3 <- ggdraw() + theme(plot.background = element_rect(fill = "#0000FF80", color = NA))
row <- plot_grid(p1, p2, nrow=2, rel_heights = c(0.4, 0.6),
labels=c("b", "c"), hjust=c(-5,-0.5), vjust=c(0.5,0))
plot_grid(p3, row, nrow=2, rel_heights = c(0.33, 0.66))
一种解决方案是禁用此剪辑:
row_grob <- ggplotGrob(row)
index <- grep("panel", row_grob$layout$name)
row_grob$layout$clip[index] = "off"
plot_grid(p3, row_grob,
nrow=2, rel_heights = c(0.33, 0.66))
或者,您可以在组装整个绘图网格后绘制标签,使用 draw_label()
。
如何使嵌套 plot_grid 图中的调整标签不隐藏在其他图下方?
这很好用:
# label 'b' is visible on top of figure a
plot_grid(ggdraw(), ggdraw(), nrow=2, labels=c("a", "b"), hjust=c(-0.5, -5), vjust=c(1,-2))
但不是这个:
# label 'b' is invisible below figure a.
plot_grid(ggdraw(),
plot_grid(ggdraw(), ggdraw(),
nrow=2, rel_heights = c(0.4, 0.6), labels=c("b", "c"), hjust=c(-5,-0.5), vjust=c(0.5,0)),
nrow=2, rel_heights = c(0.33, 0.66))
这是一个剪辑问题。 plot_grid()
使用 ggplot 绘制网格,ggplot 会裁剪掉绘图面板之外的内容。您的截止字母部分落在绘图面板之外:
p1 <- ggdraw() + theme(plot.background = element_rect(fill = "#FF000080", color = NA))
p2 <- ggdraw() + theme(plot.background = element_rect(fill = "#00FF0080", color = NA))
p3 <- ggdraw() + theme(plot.background = element_rect(fill = "#0000FF80", color = NA))
row <- plot_grid(p1, p2, nrow=2, rel_heights = c(0.4, 0.6),
labels=c("b", "c"), hjust=c(-5,-0.5), vjust=c(0.5,0))
plot_grid(p3, row, nrow=2, rel_heights = c(0.33, 0.66))
一种解决方案是禁用此剪辑:
row_grob <- ggplotGrob(row)
index <- grep("panel", row_grob$layout$name)
row_grob$layout$clip[index] = "off"
plot_grid(p3, row_grob,
nrow=2, rel_heights = c(0.33, 0.66))
或者,您可以在组装整个绘图网格后绘制标签,使用 draw_label()
。