如何对齐R中tableGrob()下的GGParagation()文本 我想要达到的目标
我试图在如何对齐R中tableGrob()下的GGParagation()文本 我想要达到的目标,r,ggplot2,grob,R,Ggplot2,Grob,我试图在ggparagration()中实现边距,但找不到任何有帮助的设置。我在ggarrange()中尝试将两种宽度设置为相同,但这不起作用,是一种解决方法。当我从ggarrange()输出中导出PDF时,现在会发生的情况是文本与PDF页面的宽度一样长。我不想改变PDF页面的宽度 代码 下面是一些示例代码: text <- paste("iris data set gives the measurements in cm", "o
ggparagration()
中实现边距,但找不到任何有帮助的设置。我在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))
text您可以使用主题(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))
库(gridExtra)
图书馆(ggpubr)
文本