Reputation: 571
I am trying to implement margins in the ggparagraph()
, but I can't find any settings which would help out. I tried setting both widths the same in ggarrange()
, but this did not work and is a workaround. What would happen now when I export the PDF from the ggarrange()
output is that the text is as long as the width of the PDF page. I do not want to alter the width of the PDF page.
Here some sample code:
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))
I altered the code sligtly from this source to suit my needs.
Thank you in advance!
Upvotes: 3
Views: 614
Reputation: 24770
You can use theme(plot.margin = )
. You can modify the numbers in the call to units()
to get just the margins you are interested in. Note that t
, r
, b
, and l
stand for top, right, bottom and left respectively.
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))
Upvotes: 1