ggplot2: label_parsed and label_wrap_gen(multi_line=FALSE) together

Viewed 1154

I want to combine the labels of two facet variables into one line, but the label contains math expression.

library(ggplot2)
dat <- data.frame(var1=rep(c("alpha[Q]==2","alpha[Q]==5"),each=2),var2=rep(c("beta[Q]==2","beta[Q]==5"),2),x=1:4,y=c(1,-1000,1000,100))

# plot 1
ggplot(dat,aes(x,y))+geom_point()+facet_wrap(~var1+var2,scale="free",labeller=label_parsed)

# plot2
ggplot(dat,aes(x,y))+geom_point()+facet_wrap(var1~var2,scale="free",labeller=label_wrap_gen(multi_line=FALSE))

plot 1 shows expression correctly, but the two variables are not combined. plot 2 combines the variables but the expression is not right. I want plot 2 to show the expression correctly.

1 Answers
Related