Reputation: 9018
I'd like to put the expression
a x b^.5 x c^.8
on a ggplot label
here is the code:
library(latex2exp)
df = data.frame(x= 1:5,y = 1:5)
ggplot(df,aes( x= x ,y = y))+geom_point()+
geom_text(x = 1 , y =1, label = TeX('$ a \\times b^.5 \\times c^.8$'))
any idea how to do that?
Upvotes: 1
Views: 140
Reputation: 416
library(latex2exp)
library(ggplot2)
library(dplyr)
tex_var <- '$ a \\times b^.5 \\times c^.8$'
# to label each point with the LaTEX expression
df = data.frame(x= 1:5,y = 1:5, z = )
ggplot(df,aes( x= x ,y = y)) +
geom_point() +
geom_text(aes( y = y+.25),label = TeX(tex_var, "text"))
# to put it as a label to the whole plot
ggplot(df,aes( x= x ,y = y)) +
geom_point() +
labs(title = TeX(tex_var, "text")) +
theme(plot.title=element_text(size=20, face="bold", color="red"))
Upvotes: 1