tex_c6 <- TeX("$\\textit{x_1}$")
ggp <- ggp + annotate("text", x = -0.6, y = -1.75, label = tex_c6, col = "darkgreen", size = 6)
error message:
Error in annotate():
! Problem while setting up geom aesthetics. Error occurred in the 2nd layer.
Caused by error in list_sizes():
! x$label must be a vector, not an expression vector.
Run rlang::last_trace() to see where the error occurred.
Called from: stop(fallback)
Warning message:
In fortify(data, ...) : Arguments in ... must be used. Problematic argument:
• show.legend = FALSE Did you misspell an argument name?
Code worked yesterday morning, failed by evening.
Why?
Your code works for me with out any changes except I invented a plot to store in ggp, since you didn't supply one. Have you tried restarting your R session?
library(latex2exp)
#> Warning: package 'latex2exp' was built under R version 4.4.3
library(ggplot2)
tex_c6 <- TeX("$\\textit{x_1}$")
DF <- data.frame(x = c(-2,-1,0,1,2), y = c(-2,-1,0,1,2))
ggp <- ggplot(DF, aes(x, y)) + geom_point()
ggp <- ggp + annotate("text", x = -0.6, y = -1.75, label = tex_c6, col = "darkgreen", size = 6)
ggp
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type
#> 'expression'
FJCC - Thank you for your reply. Yes, I have a plot for this label to go onto. I have restarted the R session more than once. I tried installing the latest upgrade to RStudio, with no change in the results, and am now running Version 2023.06.1+524 (2023.06.1+524). I have also completely shut down the computer and restarted that, in the time-honored spirit of unplugging and replugging electronics to cure what ails it. I am also running library(latex2exp). This code has worked for a very long time; it just suddenly failed yesterday during the day. I don't know if it's important, but I am on an iMac running macOS Sequoia 15.6.1.
The next thing to try is to uninstall the latex2exp package and reinstalling it. That's similar to the magic of unplugging and replugging. Reinstalling Rstudio does not have the same effect at all.
It works! I scanned through the packages that were being loaded. I found out that there were two versions of ggplot2 that were available to be loaded. One was in the User library. That one was version 4.0.0. The other version was in the System Library. That one was version 3.4.0. When I loaded both it apparently chose the later version. When I checked only 4.0.0 it did not work. When I chose only 3.4.0 it worked! Computers are wonderful, but only sometimes.
Many thanks for all your attention to this strange thing.