Nixon, John
2013-Aug-20 21:28 UTC
[R] alignment problem for italicised legend text in pdf output from a barplot
A minimal R source code file producing this is:
data=c(1,2)
pdf(file="error.pdf")
barplot(data)
legend(1.5,c(expression(italic("C.sativa"),italic("B.rapa"))),horiz=TRUE)
dev.off()
The problem is that the two italicised strings are not aligned in the pdf
output, with the string on the left being lower than the string on the right by
size of about two dots. Removing the calls to expression and italic produces
correct alignment, but italic is required in the final figure.
The R version information etc. follows.
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 14.1
year 2011
month 12
day 22
svn rev 57956
language R
version.string R version 2.14.1 (2011-12-22)
Dr. John Nixon
Research Scientist/Chercheur Scientifique
Agriculture and Agri-Food Canada / Agriculture et Agroalimentaire Canada
Office Address / Adresse du bureau:
107 Science Place, Saskatoon SK S7N 0X2
E-mail Address / Adresse courriel:
John.Nixon@agr.gc.ca<mailto:John.Nixon@agr.gc.ca>
Telephone /Téléphone 306-956-2844
Facsimile / Télécopieur 306-956-7247
Teletypewriter / Téléimprimeur 613-773-2600
Government of Canada / Gouvernement du Canada
[[alternative HTML version deleted]]
David Winsemius
2013-Aug-21 00:59 UTC
[R] alignment problem for italicised legend text in pdf output from a barplot
On Aug 20, 2013, at 2:28 PM, Nixon, John wrote:> A minimal R source code file producing this is: > > data=c(1,2) > pdf(file="error.pdf") > barplot(data) > legend(1.5,c(expression(italic("C.sativa"),italic("B.rapa"))),horiz=TRUE) > dev.off() > > The problem is that the two italicised strings are not aligned in the pdf output, with the string on the left being lower than the string on the right by size of about two dots. Removing the calls to expression and italic produces correct alignment, but italic is required in the final figure. >It's being caused by the descender of the letter "p". There are no letters with descenders in the first expression. `phantom` lets you add space and apparently does so both horizonatly which I how I've used it before and vertically as this demonstrates. Do this: data=c(1,2) pdf(file="error.pdf") barplot(data) legend(1.5,c(expression( phantom("p")*italic("C.sativa"), italic("B.rapa"))),horiz=TRUE) dev.off() -- David Winsemius Alameda, CA, USA