[R] CairoPDF and greek letter spacing

Rolf Turner rolf.turner at xtra.co.nz
Tue Jan 10 06:22:00 CET 2012

On 10/01/12 15:25, David Winsemius wrote:
> On Jan 9, 2012, at 8:19 PM, Rolf Turner wrote:
>> On 10/01/12 11:40, John Walker wrote:
>>> I have a small problem with R graphics output. When I use the lattice
>>> package and CairoPDF to generate publication quality graphs I often use
>>> the expression to create an axis title that has microlitres or
>>> micrometers as a unit. I use something like the following
>>> 'expression(paste("Length (", mu,"m )"))' as an argument to the xlabel
>>> function. The command works but the mu and 'm' have a space between
>>> them. It looks like 'u m' rather than 'um'. It only seems to happen 
>>> with
>>> the CairoPDF output on my linux machine, it's fine on the X11 device.
>>> I've fixed it in the past by importing the pdf into inkscape and
>>> manually adjusting the spacing (it's more difficult than it sounds
>>> because I can't actually adjust the spacing but have to delete the mu
>>> and re-enter it).  Is there something I'm doing wrong? Is this a known
>>> bug?  How can I fix it?
>> I can't help, but I can confirm the problem, for what *that* is worth.
>> It seems be an unfortunate interaction between lattice graphics and
>> the cairo_pdf() device.
>> The space between the "mu" and the "m" does not appear with
>> ``ordinary'' R graphics, irrespective of device, nor does it appear
>> with lattice graphics and, e.g. the pdf() device.  But it does appear
>> with lattice graphics *and* the cairo_pdf() device.
>> That probably means that the problem is subtle and will be difficult
>> to impossible to fix. :-(
> Doubtful. Do either of you realize that `paste` is a plotmath function 
> that is misused more often than correctly used (at least as judged by 
> the number o errors submitted to r-help)? I see no workable example, 
> but if I did I would be trying instead :
> expression(Length~mu*m)

You meant expression(Length==mu*m).  And yes that helps a bit, but there's
still a bit more space between the mu and the m than one would like.



There's not much in it, but there's just enough to be annoying.



P. S.  And I have never been able to figure out *anything* about how 
paste() and
expression() interact.  It is a complete mystery, and a matter of trying 
things more
or less at random until something more or less works.

         R. T.

P^2. S.  I just realised that there's more space between the letters of 
"Length" in
the cairo_pdf version, as well.  Which is, I guess, The Explanation.  Is 
it a font thing?

     R. T.

More information about the R-help mailing list