How to use subscripts in ggplot2 legends -[expression()]

If you want to incorporate Greek symbols etc. into the major tick labels, use an unevaluated expression.

1
2
3
4
5
6
7
8
9
10
11
library(ggplot2)
data <- data.frame(names=tolower(LETTERS[1:4]),mean_p=runif(4))

p <- ggplot(data,aes(x=names,y=mean_p))
p <- p + geom_bar(colour="black",fill="white")
p <- p + xlab("expressions") + scale_y_continuous(expression(paste("Wacky Data")))
p <- p + scale_x_discrete(labels=c(a=expression(paste(Delta^2)),
b=expression(paste(q^n)),
c=expression(log(z)),
d=expression(paste(omega / (x + 13)^2))))
p


Contribution from :
http://stackoverflow.com/questions/6202667/how-to-use-subscripts-in-ggplot2-legends-r

本文固定链接:http://tiramisutes.github.io/2015/12/05/expression.html 转载请注明出处!

tiramisutes wechat

热评文章