Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing parentheses in R expression

Tags:

plot

r

expression

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?

like image 241
user2455117 Avatar asked May 12 '16 21:05

user2455117


1 Answers

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

like image 154
IRTFM Avatar answered Sep 21 '22 21:09

IRTFM