Kim MILFERSTEDT
2009-Oct-29 10:49 UTC
[R] changing default character size depending on settings for mfcol: How to scale font consistently?
Dear R-users,
I would like to create pdf files with varying paper sizes. The paper
size is determine by the number of plots that I squeeze on a page using
par(mfcol).
I also add text to each of these plots. I observed that depending on the
number of plots per page, the default character size is changing,
leading to differing font sizes in my plot annotations.
I would like to use cex to scale the font size so that I obtain
identical font sizes in my pdf, independent of the size of my page in
the pdf.
My question is, how do I find out the current default for character size
so that I can calculate an appropriate scaling factor? Or are there any
better alternatives?
Below, I added an example code to produce three pdf files. Note that the
red letters in the plot have different sizes, depending on the number of
plots per page.
Thank you very much in advance!
Kim
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 10.0
year 2009
month 10
day 26
svn rev 50208
language R
version.string R version 2.10.0 (2009-10-26)
Example code
test.data <- matrix(rnorm(300, 100, 25), nrow=3, ncol = 100, byrow = TRUE)
x <- seq(1,100)
how.many.to.plot <- c(1,2,3)
for(i in 1:length(how.many.to.plot))
{
test.data.red <- matrix(test.data[1:how.many.to.plot[i],], nrow
=how.many.to.plot[i], ncol = 100)
pdf.name <- paste("test", how.many.to.plot[i],
".pdf",
sep="",collapse="")
pdf(file= pdf.name, width = 7, height=(7/5)*nrow(test.data.red))
par(mar=c(0, 0, 0, 0.0), cex = 1, oma = c(0,0,0,0), mfcol=
c(nrow(test.data.red),1))
for(j in 1:(nrow(test.data.red)))
{
plot( x,
test.data.red[j,],
ylim = c(0, max(test.data.red[j,])),
type = "l",
xaxt = "n",
yaxt = "n",
)
text( x = 30,
y = 75,
labels = LETTERS[j],
cex = 1.6,
col ="red"
)
}
dev.off()
}
--
________________________________________________
Kim Milferstedt, PhD
Postdoctoral Researcher
INRA
Laboratoire de Biotechnologie de l'Environnement
Avenue des Etangs
F-11100 Narbonne
France
phone: (+33) 04 68 42 51 87
fax: (+33) 04 68 42 51 60
email: milferst at supagro.inra.fr
Jim Lemon
2009-Oct-29 22:11 UTC
[R] changing default character size depending on settings for mfcol: How to scale font consistently?
On 10/29/2009 09:49 PM, Kim MILFERSTEDT wrote:> ... > My question is, how do I find out the current default for character > size so that I can calculate an appropriate scaling factor? Or are > there any better alternatives? >Hi Kim, You can get the current scaling with: par("cex") Jim
Apparently Analagous Threads
- mathematical expression in varnames of lattice parallel plot
- R for copying and pasting selected image files?
- removing a specific number of digist from a character string
- update index in "for" statement during calculation
- rgl.postscript generating pdf: floating xlab, font size, transparency