Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix typography in axis labels

Tags:

Preamble: I want to create publication-grade graphics from R without postprocessing. Other researchers at my institute always perform postprocessing in a graphics software (such as Adobe Illustrator). I am hoping to avoid this.

My gripe is that R doesn’t use the correct minus sign for negative numbers (especially in plot axes):

plot(-20:-1, rnorm(20) + 1 : 20)

plot with negative numbers

(I’ve circled the offenders for your consideration.)

As somewhat of a typography nerd (it’s true! Check my Careers CV!) this is unacceptable. I need to use the correct Unicode character ᴍɪɴᴜꜱ ꜱɪɢɴ (U+2212, “−”) here. A friend of mine achieves this by replacing all minus signs in Adobe Illustrator prior to publication but I can’t help but think that there must be a better way – from within R – to accomplish this; and one that doesn’t force me to manually replace all axis labels.

(I’m not currently using ggplot2 but if there’s a solution which only works with ggplot2 I’ll gladly take it.)

like image 240
Konrad Rudolph Avatar asked Feb 08 '13 20:02

Konrad Rudolph


People also ask

How do I change the Font on an axis label in Excel?

To change the text font for any chart element, such as a title or axis, right–click the element, and then click Font. When the Font box appears make the changes you want.


2 Answers

Perhaps draw the axis and labels manually, rather than accepting the defaults?

plot(-20:-1, rnorm(20) + 1 : 20, xaxt="n")
Axis(-20:-1, at=seq(-20,-5,5), side=1,
  labels=paste("\U2212",seq(20,5,-5),sep=""))

enter image description here

like image 141
Joshua Ulrich Avatar answered Sep 21 '22 15:09

Joshua Ulrich


Another way which is almost the same as the one provided by Joshua Ulrich, except that you can let R compute the axis ticks :

plot(-20:-1, rnorm(20) + 1 : 20, xaxt="n")
at <- axTicks(1, usr=par("usr")[1:2])
labs <- gsub("-", "\U2212", print.default(at))
axis(1, at=at, labels=labs)

enter image description here

like image 26
juba Avatar answered Sep 23 '22 15:09

juba