1

Im trying to print $\lambda = $ lambda" (where lambda outside of the dollar signs is a variable) on the xlabel of a plot I'm making in R using the latex2exp package. When I use:

xlab = paste(TeX(r'($\\lambda = $)'), lambda)

as is instructed for R version 4.0 and above (which I am using) it gives me:

", "", lambda, , , , phantom() == phantom(

on the xlabel in the pdf I created of the plot. When I use:

xlab = paste("$\\lambda = $", lambda)

It literally prints the characters:

$\lambda = $ lambda

Im not sure what the significance of only one \ showing up instead of two backslashes is. I tried asking about this problem in a different way in this thread: TeX("$\lambda$") doesn't work in R , but I couldnt figure it out. I dont want to use the sweave file method with the kntir and tikzDevice packages, I kind of want to figure out why latex2exp isnt working. Please help

3
  • This isn't really about TeX, but try xlab = TeX(paste0("$\\lambda = ", lambda, "$")).
    – chsk
    Apr 12, 2021 at 7:43
  • If the suggestion by @chsk does not work, then, continuing the comments from the other question: you said that a single plot with latex2exp works properly, so you concluded that there is a problem with your code for generating multiple plots. To find out what the problem is you therefore need to show the code that actually reproduces the problem. Show a full R script that, when executed from start to finish in R 4.x, results in the output you describe. Try to make it minimal, i.e., remove statements or details that are not needed to reproduce the problem.
    – Marijn
    Apr 12, 2021 at 7:44
  • You might want to consider asking R-specific question on a different, better suited site, maybe stackoverflow.com. Here it is hardly on topic. May 20, 2021 at 10:13

0

You must log in to answer this question.

Browse other questions tagged .