Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding greek character and asterisk (*) to axis title

Tags:

r

label

I want to add a greek character to the x-axis of my histogram plot in R. I can write the greek character alone or with the hat, but the problem is that I need this character to be come with a hat and asterisk () together. More specifically, I want the something like hat(phi^). Here is what I have done:

x = rnorm(1000)
hist( x, nclass = 100, cex.lab=1.5, xlab = expression(hat(phi^*)), 
ylab="Frequency", main="", cex.axis=1.5 )

Thanks.

like image 639
user27808 Avatar asked Oct 16 '25 20:10

user27808


1 Answers

What about using ggplot2 instead of base R. You can then use latex2exp::TeX to use (some) LaTeX expressions in the axes labels.

set.seed(2018)
x = rnorm(1000)

library(ggplot2)
library(latex2exp)

ggplot(data.frame(x = x), aes(x)) +
    geom_histogram(bins = 100) +
    theme_minimal() +
    xlab(TeX("$\\widehat{\\phi^*}$"))

enter image description here

You need to escape the backslashes with an extra backslash and wrap math expressions inside $ delimiters (just as in regular LaTeX inline math). I used \widehat{}, but you can also use hat{} instead.

like image 61
Maurits Evers Avatar answered Oct 18 '25 11:10

Maurits Evers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!