3

我想要达到的目标

我正在尝试在 中实现边距ggparagraph(),但找不到任何有用的设置。我尝试将两个宽度设置为相同ggarrange(),但这不起作用并且是一种解决方法。当我从输出中导出 PDF 时,现在会发生的情况ggarrange()是文本与 PDF 页面的宽度一样长。在此处输入图像描述我不想改变 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))

我从这个来源稍微修改了代码以满足我的需要。

先感谢您!

4

1 回答 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))

在此处输入图像描述

于 2020-12-17T23:51:52.453 回答