ecjb
ecjb

Reputation: 5459

Bold text in text of the axis in R using TeX()

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

Upvotes: 0

Views: 998

Answers (1)

m0nhawk
m0nhawk

Reputation: 24228

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

Upvotes: 2

Related Questions