[R] Spacing around \cdot (%.%) unequal in pdf

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri Feb 8 11:27:46 CET 2019

>>>>> Pascal A Niklaus 
>>>>>     on Wed, 6 Feb 2019 19:48:49 +0100 writes:

    > I am struggling labeling an axis in a plot.
    > Here is a minimal example illustrating the point:

    > pdf("mve.pdf",width=5,height=5)
    > ypos <- c(1:3) * 1e6
    > ylabs <- sapply(ypos/1e6, function(i) as.expression(bquote(.(i)%.%10^6)))
    > plot(rep(1,3), ypos, yaxt="n", ylab="")
    > axis(2, at=ypos, labels=ylabs, las=1)
    > dev.off()

    > First, I find the space left and right of the \cdot operator rather 
    > larger. Is there a way to decrease it?

    > Second, and more important, in the generated PDF, the space left of the 
    > dot is much bigger, it looks as if it was typeset as e.g. "3 *10^6".

Vaguely related:   I have advertized my  eaxis()  and
pretty10exp() functions in package 'sfsmisc' for doing what you do above more
generally and automatically:

if(!require("sfsmisc")) {
  install.packages("sfsmisc") ; library("sfsmisc")

ypos <- c(1:3) * 1e6
plot(rep(1,3), ypos, yaxt="n", ylab="")
## e.g.,
eaxis(2, at = ypos, labels = pretty10exp(ypos, drop.1=TRUE))

gives a nice plot for me, not using 'cdot' but rather

  > pretty10exp(ypos, drop.1=TRUE)
  expression(10^6, 2 %*% 10^6, 3 %*% 10^6)

    > Thanks for any hint
    > Pascal

You are welcome!

Martin Maechler
ETH Zurich and R Core Team

More information about the R-help mailing list