# This function creates figures made to be inserted
# in a Latex document (US-letter with "normal" margins)
# By default, the figures should take 100% of the
# text width. If so, the size of the text in the figures
# will be exact.
# You need pdftools and knitr to display PDFs in the viewer pane with fit.off
if(require(pdftools) && require(knitr)){
tmpFile = file.path(tempdir(), "pdf_examples.pdf")
pdf_fit(tmpFile, pt = 8)
plot(1, 1, type = "n", ann = FALSE)
text(1, 1, "This text will be displayed in 8pt.")
fit.off()
pdf_fit(tmpFile, pt = 12)
plot(1, 1, type = "n", ann = FALSE)
text(1, 1, "This text will be displayed in 12pt.")
fit.off()
pdf_fit(tmpFile, pt = 12, sideways = TRUE)
plot(1, 1, type = "n", ann = FALSE)
text(1, 1, "This text will be displayed in 12pt if in sideways.")
fit.off()
# If we reduce the end plot width but keep font size constant
# this will lead to a very big font as compared to the plot
pdf_fit(tmpFile, pt = 8, width = "50%")
plot(1, 1, type = "n", ann = FALSE)
text(1, 1, "This text will be displayed in 8pt\nif in 50% of the text width.")
fit.off()
}
Run the code above in your browser using DataLab