如何在 R 中的 tableGrob() 下对齐 ggparagraph() 文本
How to align ggparagraph() text under tableGrob() in R
我想达到的目标
我正在尝试在 ggparagraph()
中实现边距,但找不到任何有用的设置。我尝试在 ggarrange()
中将两个宽度设置为相同,但这没有用,是一种解决方法。现在,当我从 ggarrange()
输出导出 PDF 时,文本与 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))
我从这个 source 中稍微修改了代码以满足我的需要。
提前致谢!
您可以使用 theme(plot.margin = )
。您可以修改对 units()
的调用中的数字以获得您感兴趣的边距。请注意 t
、r
、b
和 l
分别代表上、右、下、左
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))
我想达到的目标
我正在尝试在 ggparagraph()
中实现边距,但找不到任何有用的设置。我尝试在 ggarrange()
中将两个宽度设置为相同,但这没有用,是一种解决方法。现在,当我从 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))
我从这个 source 中稍微修改了代码以满足我的需要。
提前致谢!
您可以使用 theme(plot.margin = )
。您可以修改对 units()
的调用中的数字以获得您感兴趣的边距。请注意 t
、r
、b
和 l
分别代表上、右、下、左
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))