1

I am trying to write LaTex formulas in ggplot titles and labels by using Tex function from latex2exp, like

library(tidyverse)
library(latex2exp)

x = c(1,2,3)
y = c(10, 3, 2)
ggplot(data = data.frame(x = x, y = y), aes(x,y)) +
  geom_point() +
  labs(title = TeX("$s^2$"))

which results in Error in str2expression(rendered): "could not find function "str2expression". How can I fix it?

Brzoskwinia
  • 371
  • 2
  • 11
  • 2
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Mar 18 '22 at 08:19
  • 2
    @stefan sorry, I fixed it – Brzoskwinia Mar 18 '22 at 08:26
  • 1
    Works fine using R 4.1.2, ggplot2 3.3.5, latex2exp 0.9.3 on my Mac. – stefan Mar 18 '22 at 08:39
  • You likely need to update your packages. Use `update.packages(ask=FALSE)` to do that. If it still fails, you'll need to update R as well. – user2554330 Mar 18 '22 at 09:20

0 Answers0