[R] ggplot expressions

Troels Ring tring at gvdnet.dk
Mon Mar 20 12:42:11 CET 2017


Dear friends - here is an example of something that I find annoying

library(ggplot2)
DDF <- data.frame(x=x<-seq(1,10),y=x^2)
G <- ggplot(data=DDF,aes(x=x,y=y)) + geom_point()
GG<-G+ylab(expression(paste("Total ",CO[2]," halved")))
GG
GG+annotate("text",x=5,y=50,label=expression(paste("Total ",CO[2]," 
halved")))

On my system, R version 3.3.2 (2016-10-31) Windows - the third line 
produces the wanted formatting of CO2  with "2" lowered - while the last 
line produces an error  "invalid 'type' (expression) of argument" - with 
exactly the same string - how comes?

Beautiful ggplot is not exactly low in documentation but finding the 
right stuff is not always easy (for me:-))

Best wishes
Troels Ring, MD
Aalborg, Denmark



More information about the R-help mailing list