Resizing parentheses in R expression
Asked Answered
C

1

9

I would like my axis label to read something like

(m²)

with the height of the parentheses a little larger to match the superscript 2, but the parentheses nonetheless inline.

However, I either get parentheses that are too small, via something like

parse(text='group("(",m^{2},")")')

which yields

small parentheses

or parentheses that are too big and out-of-line, via something like

parse(text='bgroup("(",m^{2},")")')

which yields

large parentheses

Can I not do this in R?

Update:

As per the suggestion of user @42-, I've also tried scriptstyle. However, this makes the parenthesized text much smaller. It's particularly noticeable with neighboring text. For instance,

parse(text='Area~~(scriptstyle(m^{2}))')

would yield

scriptstyle ex1

I realize the workaround would be using something like

parse(text='scriptstyle(Area~~(m^{2}))')

which yields

scriptstyle ex2

and then manually upscaling font size to compensate, but is there a fix or alternative that won't require this kind of guesstimation?

Charactery answered 12/5, 2016 at 21:17 Comment(0)
T
9

Do you want;

plot(1,1, main=parse(text='scriptstyle( bgroup("(",m^{2},")"))') )

Or perhaps:

plot(1,1, main=parse(text='"("*scriptstyle(m^{2})*")"') )

enter image description here

A third altermative is to use "phantom()" which will reserve space equivalent to its argument. I found by experimentation that you could get parentheses that were not so "descend-ful" using:

plot(1,1, main=parse(text='"("*phantom(m^2)*")"') ,cex.main=1.6)

And then filling in the gap with:

title(main=expression(m^2) )

enter image description here

And it further twerking is needed, one can adjust the level of text relative to the "box" in units of text lines with title(main= <expression> , line= 2.5)

 plot(1,1) ; title( main=expression(Area(phantom("   "))) ,cex.main=1.5, line=1.5)
 title(main=expression(phantom('Area(')*m^2) ,line=1.5)

enter image description here

Tera answered 12/5, 2016 at 21:40 Comment(5)
Useful syntax! But is there any way to do this while making the parentheses larger/higher rather than making the text inside smaller? It's really apparent if there is surrounding text, like parse(text='Area~~(scriptstyle(m^{2}))')Charactery
Plotmath is but a poor step child of true LaTeX. You may need either LaTeX or MathML in Markdown.Tera
I see. Is there a way to predict the scaledown in font size (see updated question)?Charactery
The grid package has features that determine the size of text.Tera
Also base graphics has strwidth and strheight but ?strheight says it does not account for the "descenders" in text, but apparently measures the full height of a plotmat bounding box.Tera

© 2022 - 2024 — McMap. All rights reserved.