简体   繁体   中英

Using subscript and line break at the same time in plot titles in R

I wish to include a subscript and a title running into two lines at the same time but am not getting desired result with following commands:

base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n'  ~.(compare)~ 'minus'~.(base)))

I wish to insert a line break after 'Flux Difference' but its not happening instead this term is hanging nowhere. Please help me.

Thanks, Munish

This is a fairly common request and there is no really clean answer. Plotmath will not accept a "\\n" (and the help page documents this.) One dodge is to use each line as an argument to the plotmath function atop . The other plotmath trick sometimes of use is phantom with an empty argument list to allow the tilde not to throw an error, but that is not needed here:

plot (1, 1, main = bquote( atop('Annual mean' ~CO[2] ~'Flux Difference:' , 
                                     .(compare)~ 'minus'~.(base))) )

在此处输入图片说明

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