0

I wish to print a text in the title in two lines but am not able to achieve desired output because of subscript present in the text. Following is the e.g of the text that I want in two lines.

plot(1,main=expression(paste(CO[2]~'Flux (kg C ', m^-2,' ',s^-1,')')))

BUT using line break as in following command does not give desired result of bringing (only) the text following it in new line:

plot(1,main=expression(paste(CO[2]~'Flux \n(kg C ', m^-2,' ',s^-1,')')))

Please help me with this issue. Thanks in advance

Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113
Munish
  • 667
  • 3
  • 13
  • 34
  • Didn't you ask this before and get the same answer? http://stackoverflow.com/questions/13317428/using-subscript-and-line-break-at-the-same-time-in-plot-titles-in-r/13317495#13317495 – Bryan Hanson Mar 28 '13 at 20:19

1 Answers1

3

You can do this with the atop function.

plot(1,main=expression(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')'))))

enter image description here

Since the lheight par doesn't affect expressions, if you want tighter spacing between the lines, you can use the following.

plot(1,main=expression(textstyle(atop(CO[2]~'Flux', paste('(kg C ', m^-2,' ',s^-1,')')))), 
     cex.main=2)

enter image description here

Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113
  • it works well, any suggestion on decreasing (or increasing) the gap between the two lines? – Munish Mar 28 '13 at 18:16
  • @Munish the usual `par` value that would control this is `lheight`, but this doesn't have an affect on expressions. However, if in my answer you wrap the call to `atop` in `textstyle` and set `cex.main` to, say, 2 in the `plot` call, you'll get a tighter title of approximately the same size. – Matthew Plourde Mar 28 '13 at 18:32
  • This answer just saved me hours of futile coding. Thanks! – Nan Sep 25 '13 at 12:20