My goal is to annotate a plot made with ggplot2 by placing an equation in white space within the plot using the package latex2exp
For example, given the equation:
eqn <- "$\\textbf{Volume}(ml) = 0.035 \\cdot \\textbf{CSA}(mm^2) + 0.127 \\cdot \\textbf{age}(months) - 7.8$"
Running the following code in R 3.5:
library(ggplot2)
library(latex2exp)
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_point() +
annotate("text", x = 4, y = 40, label=TeX(eqn), hjust=0, size = 5)
My example code fails with the error below:
Error in stats::complete.cases(df[, vars, drop = FALSE]) :
invalid 'type' (expression) of argument
What am I doing wrong?