【问题标题】:Page number position using marrangeGrob and ggsave in R在R中使用marrangeGrob和ggsave的页码位置
【发布时间】:2018-04-05 05:17:29
【问题描述】:

这是一个微不足道的问题,但我仍然想解决这个问题。我正在使用marrangeGrobggsave 导出一系列图表。我想将使用marrangeGrob 生成的页码的默认位置更改为从页面顶部到右下角。

基于这个问题; Remove page numbers from marrangeGrob (or arrangeList) pdf,我可以包含参数top = NULL, bottom = quote(paste("page", g, "of", pages)) 将页码移到每页的底部,但页码仍然在中间。

我可以在paste 语句的开头添加很多空间,因此:" page" 但这看起来真的很难看。有没有更好的方法来做到这一点?

样本数据

library(ggplot2)
library(gridExtra)

# Create some plots
p1 <- qplot(mpg, wt, data = mtcars, colour = cyl)
p2 <- qplot(mpg, data = mtcars) + ggtitle("title")
p3 <- qplot(mpg, data = mtcars, geom = "dotplot")

# Combine into a list, and change where page numbers will appear
Export <- marrangeGrob(list(p1, p2, p3), nrow = 2, ncol = 1, top = NULL, 
               bottom = quote(paste("page", g, "of", npages)))

# Export to a pdf file
ggsave(filename = "multipage.pdf", Export, width = 7, height = 10, units = "in")

【问题讨论】:

    标签: r gridextra


    【解决方案1】:

    你可以传递一个 grob 而不是一个字符串,

    bottom = quote(grid::textGrob(paste("page", g, "of", npages), x=1, hjust=1))
    

    【讨论】:

    • 谢谢,很好用。我稍微修改了调用,以便文本不会卡在页面边缘; x = 0.9, vjust = -0.2
    猜你喜欢
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    相关资源
    最近更新 更多