Adding greek character to axis title

前端 未结 6 983
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 03:37

I want to add a greek character to the y-axis of my barplot in R.
The problem is that I need this character to be integrated in the title. I want to write:



        
相关标签:
6条回答
  • 2020-11-29 03:44

    And if you want to substitute variables in the text, use bquote. For instance, if you have a variable mu and want to show it in the title, then use the following idiom:

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

    The part enclosed in .() will be substituted, so that the value of mu will be printed and not the greek "mu" character. Consult the R help on bquote for details.

    enter image description here

    0 讨论(0)
  • 2020-11-29 03:45

    I give an updated answer to Chase's plot example (from 2011) above while working with Windows 10 with a suitable TrueType Font with the help package utf8 on R 3.62. In my answer, I assign a value to μ. The unicode characters I just call out by their hex (??) code. The space is just a 'space' inside quotes. See my answer here:

    See also: http://www.unicode.org/Public/10.0.0/ucd/UnicodeData.txt

    utf8-package {utf8}

    # pi small case
    utf8_print("\u03C0")
    "π"
    # sigma small case
    utf8_print("\u03C3")
    "σ"
    
    μ <- abs(digamma(1))
    μseq <- seq(μ,3*μ,μ)
    dev.new()
    plot(μseq, ylab = "Diameter of apeture ( μ m)",
      , xlab = "Force spaces with ~ μ  \u03C0  \u03C3  \u03C0 ",
      , main = "This is another Greek character with space \u03C3")
    #
    

    0 讨论(0)
  • 2020-11-29 03:50

    And, in case you were dealing with an estimated quantity, plotmath{grDevices} also offers the possibility of adding a hat to your greek letter:

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

    The mu enclosed in hat() does the trick.

    0 讨论(0)
  • 2020-11-29 03:54

    I think I followed your question properly. The ~ forces a space between characters in a call to 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

    0 讨论(0)
  • 2020-11-29 03:57

    This should be much more straight forward with latex2exp:

    require(latex2exp)
    plot(1, xlab = TeX('$\\mu$'))
    
    0 讨论(0)
  • 2020-11-29 04:04

    If you're using plotmath{grDevices}, the main help page (plotmath) contains an example of what you appear to want:

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

    or for your case, I guess:

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

    Does this work for you?

    0 讨论(0)
提交回复
热议问题