首页 > 解决方案 > 如何更改“grid_arrange_shared_legend”中常见图例的标题?

问题描述

我正在使用“grid_arrange_shared_legend”函数来绘制多个图。生成的图例有一个标题,它是数据框中列的命名方式。但是,我需要将其修改为其他内容。

grid_arrange_shared_legend <- function(plots) {
  g <- ggplotGrob(plots[[1]] + theme(legend.position="bottom"))$grobs
  legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
  lheight <- sum(legend$height)
  grid.arrange(
    do.call(arrangeGrob, lapply(plots, function(x)
      x + theme(legend.position="none"))),
    legend,
    ncol = 1,
    heights = unit.c(unit(1, "npc") - lheight, lheight))
}

标签: rggplot2legend-properties

解决方案


推荐阅读