Reputation: 267
I need to pass three variables to a ggtitle. Something like
lambda=1
alpha=0.9
mem=2000
g <- ggplot(data=data.frame(x=0,y=0))+geom_point(aes(x=x,y=y))
s<-sprintf("\\alpha=%f, \\lambda=%f, \\memory=%g",alpha,lambda,mem)
g+ggtitle(s)
but unfortunately no greek letters are shown (I know there is expression but I could not figure out how to use it). With just one variable, there is a thread with a solution (bquote). For passing multiple variables there is another thread but does not treat greek symbols.
Many thanks
Upvotes: 5
Views: 2715
Reputation: 206167
In order for the greek letters to render properly, you need to build an expression, not a string. Here's one way to do that
g + ggtitle(bquote(list(alpha==.(alpha), lambda==.(lambda), memory==.(mem))))
bquote()
will work with any number of variables, not just one.
Upvotes: 11