I have been using the latex2exp
package for many years, but ever since it switched to the latest version (using the "raw" syntaxis), it has ceased to function (the old syntaxis does not work either). I am working on Windows and have updated all my R and LaTeX libraries, but I am still encountering issues (I have attached a screenshot).
MWE
library(latex2exp)
a <- 1:100
plot(a, a^2, xlab=TeX("$\\alpha$"), ylab=TeX("$\\alpha^2$"))
Also, trying to reproduce this example
library(latex2exp)
library(tidyverse)
library(ggplot2)
x <- seq(0, 4, length.out=100)
alpha <- 1:5
data <- map_df(alpha, ~ tibble(v=.*x^., x=x, alpha=.))
p <- ggplot(data, aes(x=x, y=v, color=as.factor(alpha))) +
geom_line() +
ylab(TeX(r'($\alpha x^\alpha$, where $\alpha \in 1\ldots 5$)')) +
ggtitle(TeX(r'(Using $\LaTeX$ for plotting in ggplot2. I $\heartsuit$ ggplot!)')) +
coord_cartesian(ylim=c(-1, 10)) +
guides(color=guide_legend(title=NULL)) +
scale_color_discrete(labels=lapply(sprintf(r'($\alpha = %d$)', alpha), TeX))
# Note that ggplot2 legend labels must be lists of expressions, not vectors of expressions
print(p)
from the library help page Using latex2exp
I get a plot with all the labels wrong
Any idea what could be causing this problem?