1

How to render bold text in plot in R using TeX?

TeX("$\\alpha$")
TeX("The ratio of 1 and 2 is $\\frac{1}{2}$")

a <- 1:100
plot(a, a^2, xlab=TeX("$\\alpha$ bold text"), ylab=TeX("$\\alpha^2$ bold text"))

I tried TeX("$\\alpha$ \textbf{bold text}") and TeX("$\\alpha$ $\textbf{bold text}$") without success

M--
  • 25,431
  • 8
  • 61
  • 93
ecjb
  • 5,169
  • 12
  • 43
  • 79
  • Possible duplicate of [How to make beta italic and bold in axis label and P italic and bold in text](https://stackoverflow.com/questions/24458090/how-to-make-beta-italic-and-bold-in-axis-label-and-p-italic-and-bold-in-text) – M-- Nov 20 '18 at 21:31
  • https://stackoverflow.com/questions/1395105/getting-latex-into-r-plots – M-- Nov 20 '18 at 21:33
  • Thank you for your comment Masoud – ecjb Nov 21 '18 at 21:35
  • 2
    For those who downvoted my question, I would be glad to have the reason why the question was downvoted: If 1. the style of the question or the accuracy of the question is not good enough, just write it : I'm very eager to learn and improve how to write better questions. If it’s 2. because the question is a duplicate, just write as an answer: I would more than glad to upvote it and accept it as an answer. If 3. there is another reason that I didn’t get please write it as well. But I must say that I find the attitude of just downvoting “for free” without any explanation irritating and useless – ecjb Nov 21 '18 at 21:46

1 Answers1

2
library(latex2exp)

TeX("$\\alpha$")
TeX("The ratio of 1 and 2 is $\\frac{1}{2}$")

a <- 1:100
plot(a, a^2, xlab=TeX("$\\alpha$ \\textbf{bold text}"), ylab=TeX("$\\alpha^2$ \\textbf{bold text}"))

You need to use double slash in front of the command, then you will get the result:

enter image description here

m0nhawk
  • 22,980
  • 9
  • 45
  • 73