gpt4 book ai didi

从 marrangeGrob(或 arrangeList)pdf 中删除页码

转载 作者:行者123 更新时间:2023-12-04 09:06:37 24 4
gpt4 key购买 nike

gridExtra 中的

marrangeGrob 在行、列和页面中排列 grob(在我的例子中通常是 ggplots)。它还对页面进行编号。

require(ggplot2)
require(plyr)
require(gridExtra)

p <- function(plotdata) {
x <- ggplot(plotdata, aes(wt, mpg)) +
geom_point() +
ggtitle(plotdata$gear[1])
return(x)
}

all <- dlply(mtcars, .(gear), p)

allarranged <- do.call(marrangeGrob, c(all, nrow=1, ncol=2))
ggsave("multipage.pdf", allarranged, width=12)

这是一个愚蠢但可重现的例子。

现在检查 str(allarranged[[1]]) 的输出以显示页码对象。精简到最基本的,它们就在这里:

[[1]]
$ children :List of 5
..$GRID.frame.1925:List of 6
.. ..$ children :List of 5
.. .. ..$ GRID.cellGrob.1927:List of 10
.. .. .. ..$ children :List of 1
.. .. .. .. ..$ GRID.text.1845:List of 11
.. .. .. .. .. ..$ label : chr "page 1 of 2"

我在那里写了前几行,因为我在将 str() 的输出写入文件时遇到了问题。不过,这一点是成立的。 $label 是许多祖 parent 的问题 child 。每个 arrangelist 还有几个 $label(arrangeListarrangeGrob 的输出类)。

一旦你弄清楚了 $label 的位置,就可以了: allarranged[[1]]$children$GRID.frame.1770$children$GRID.cellGrob.1772$children$GRID.text.1690$label <- NULL

但是如何预测整棵树,或者通过它递归寻找 $label?如果这不是一个有趣的问题,我可能会联系 gridExtra 维护者。

最佳答案

您需要将 top=NULL 传递给 marrangeGrob

all <- dlply(mtcars, .(gear), p)

allarranged <- do.call(marrangeGrob, c(all, nrow=1, ncol=2, list(top=NULL) ))
ggsave("multipage.pdf", allarranged, width=12)

关于从 marrangeGrob(或 arrangeList)pdf 中删除页码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18887758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com