Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to superscript a - (minus symbol) in a legend title with qpolot in ggplot2 in R

I'm trying to superscript a '-' straight after a subscript 4 in an axis title in ggplot2 using bquote. I'm so close! The following gives me everything EXCEPT a small, superscript - straight after the subscript 4:

qplot(uptake, data = CO2) +  
ylab(bquote('Membrane available NH '[4]*'-N (  '*mu*'g' ~ resin^-1* ~ 14~day^-1*')'))

I've tried playing around the ^, for example:

qplot(uptake, data = CO2) +  
ylab(bquote('Membrane available NH '[4]*^-'-N (  '*mu*'g' ~ resin^-1* ~ 14~day^-1*')'))

But get error messages such as:

Error: unexpected '^' in "qplot(uptake, data = CO2) +  
ylab(bquote('Membrane available NH '[4]*^"

Clearly I'm not expressing the ^ correctly.

Any help would be greatly appreciated.

Many thanks!

like image 991
Amanda Avatar asked Jan 25 '26 06:01

Amanda


1 Answers

I thought what was being requested was an extra space between the subscripted 4 and the superscript minus. Using phantom() is one method. The length of the "space" is the same as the space needed to fit the character value (at 0.67 magnification):

 NH[4]^{phantom("A")~"-"}

This is a guess at what you might want. I took out as many quotes as possible and used cdots instead of juxtaposition is some places. Obviously your tastes or those of your editors) may vary:

qplot(uptake, data = CO2) +  
   ylab(bquote(Membrane~available~NH[4]^{phantom("__")*'-'}-
                N *(  mu %.% g [ resin]^-1 %.% ~ 14~day^-1)))

If it's suppose to be micrograms then use mu*g~

like image 77
IRTFM Avatar answered Jan 26 '26 20:01

IRTFM