如何在R中使用tableGrob()将ggparagraph()文本对齐到表格底部

3

我想要实现的目标

我正在尝试在ggparagraph()中实现边距,但是我找不到任何可以帮助我的设置。我尝试在ggarrange()中将两个宽度设置为相同,但这并没有起作用,而且这是一种变通方法。现在,当我从ggarrange()输出中导出PDF时,文本的长度与PDF页面的宽度一样。enter image description here我不想改变PDF页面的宽度。

代码

这里是一些示例代码:

text <- paste("iris data set gives the measurements in cm",
              "of the variables sepal length and width",
              "and petal length and width, respectively,",
              "for 50 flowers from each of 3 species of iris.",
              "The species are Iris setosa, versicolor, and virginica.", sep = " ")
text.p <- ggparagraph(text = text, face = "italic", size = 11, color = "black")
stable <- desc_statby(iris, measure.var = "Sepal.Length",
                      grps = "Species")
stable <- stable[, c("Species", "length", "mean", "sd")]
stable.p <- tableGrob(stable, rows = NULL, 
                        theme = ttheme("mOrange"))

ggarrange(stable.p, text.p, 
          ncol = 1, nrow = 2,
          heights = c(1, 0.5))

我稍加更改了这个来源的代码以适应我的需求。
提前感谢你!
1个回答

1
你可以使用theme(plot.margin = )。你可以修改调用units()的数字,以获得你感兴趣的边距。请注意,trbl分别代表顶部、右侧、底部和左侧。
library(gridExtra)
library(ggpubr)
text <- paste("iris data set gives the measurements in cm",
              "of the variables sepal length and width",
              "and petal length and width, respectively,",
              "for 50 flowers from each of 3 species of iris.",
              "The species are Iris setosa, versicolor, and virginica.", sep = " ")

text.p <- ggparagraph(text = text, face = "italic", size = 11, color = "black") +
            theme(plot.margin = unit(c(t = 0, r = 12, b = 3, l = 12),"lines"))

stable <- desc_statby(iris, measure.var = "Sepal.Length",
                      grps = "Species")
stable <- stable[, c("Species", "length", "mean", "sd")]
stable.p <- tableGrob(stable, rows = NULL, 
                      theme = ttheme("mOrange"))

ggarrange(stable.p, text.p, ncol = 1, nrow = 2, heights = c(1, 0.5))

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接