简体   繁体   中英

Combine an expression and a new line in ggplot2 legend

I'm probably asking too much, anyway I would like to create a legend title on two lines, where the first line contains an expression (the greek symbol \\Phi, with subscript 10 ), and the second line is [.] . It should look like this:

在此处输入图片说明

I tried

p <- ggplot(mtcars,aes(x=wt,y=mpg,color=qsec))+
     geom_point()+
     labs(color=expression(atop(Phi["10"]),group("[",.,"]")))

But this doesn't print the lower line:

在此处输入图片说明

Can you help?

You simply have a bracket in the wrong place. It should be atop(something, somethingelse)

p <- ggplot(mtcars,aes(x=wt,y=mpg,color=qsec))+
     geom_point()+
     labs(color=expression(atop(Phi["10"],group("[",.,"]"))))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM