5

How do one use a math-mode in knitr? For example as a label for X-Y axis:

<<fe, echo=FALSE, sanitize=TRUE, dev="tikz">>=
    plot(1:10, main="${}^{57}Fe$", xlab="$\\\\lambda$", ylab="\\\\$I\\\\$", pch=20, family="CM Roman")
@

This produces the $I$ and $lambda$ as a labels.

5

To use latex (such as math mode) directly in the images, you will need to install the R package tikzDevice, and also the Latex package tikz for Latex (and you will need to explicitly put \usepackage{tikz} in your document).

<<fe, dev="tikz", fig.cap = "${}^{57}Fe spectrum$", echo=FALSE>>=
    plot(1:10, xlab="$\\lambda$", ylab="$I$", pch=20, family="CM Roman")
@

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.