我想将两个方面变量的标签合并为一行,但标签包含数学表达式。
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))
Run Code Online (Sandbox Code Playgroud)
图 1 正确显示了表达式,但两个变量未组合。图 2 组合了变量,但表达式不正确。我希望 plot 2 正确显示表达式。
我认为您正在寻找以下内容.multi_line = FALSE(注意.):
ggplot(dat,aes(x,y))+
geom_point()+
facet_wrap(~var1+var2,scale="free",
labeller = labeller(.cols = label_parsed, .multi_line = FALSE))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
952 次 |
| 最近记录: |