Adding a Greek character to the axis header

I want to add a greek symbol to the y axis of my burplot in R.
The problem is that I need this character to be included in the header. I want to write:

Diameter of aperture ("mu"m) 

in the axis label.

FROM

 ylab=expression() 

I can write a Greek symbol,

 ylab="axis title" 

I can write a headline with the correct spaces between words.

But I cannot find a way to combine all this and write the corresponding label with the Greek word in the axis label. I hope I was clear enough.

+48
r unicode labels plotmath
May 18 '11 at 12:41
source share
5 answers

If you use plotmath{grDevices} , the main help page ( plotmath ) contains an example of what you think is needed:

 xlab = expression(paste("Phase Angle ", phi)) 

or for your case, I think:

 ylab = expression(paste("Diameter of aperture ( ", mu, " )")) 

Does this work for you?

+54
May 18 '11 at 13:00
source share

I think I followed your question correctly. ~ forces a space between characters when calling expression() . Is this what you want?

 plot(1:3, ylab = expression("Diameter of apeture (" * mu ~ "m)"), , xlab = expression("Force spaces with ~" ~ mu ~ pi * sigma ~ pi) , main = expression("This is another Greek character with space" ~ sigma)) 

enter image description here

+27
May 18 '11 at 13:01
source share

And if you want to replace the variables in the text, use bquote . For example, if you have a mu variable and want to show it in the header, use the following idiom:

 mu <- 2.8 plot(1:3, main=bquote(mu == .(mu))) 

The part enclosed in .() Will be replaced so that the mu value is printed, not the Greek symbol "mu". See R bquote .

enter image description here

+10
Feb 11 '15 at 13:20
source share

This should be much more straight forward with latex2exp :

 require(latex2exp) plot(1, xlab = TeX('$\\mu$')) 
+4
Mar 08 '17 at 13:37 on
source share

And, if you were dealing with an estimated amount, plotmath{grDevices} also offers the ability to add a hat to your Greek letter:

 ylab = expression(paste("Diameter of aperture ( ", hat(mu), " )")) 

mu enclosed in hat() performs the trick.

+2
Mar 25 '15 at 8:29
source share



All Articles