Skip to content

expression() and axis labels

6 messages · David Winsemius, Joshua Wiley, Thomthom +1 more

#
Hi everyone!

I tried to look up in the previous topics whether there was something
similar to my question but I think there's nothing corresponding...

Anyway! Here is my problem:

I have a plot (qplot()) in which I want to insert axis labels with the
following text:

kg NH4+ N-equiv. * ha-1 yr-1 (well... 4 smaller and down and + as a power
(the same for the -1) but I am sure you understood what I meant).

So, in my code, I typed : 

qplot(...., xlab="Amount of N-fertilizer" expression(kg NH[4]^+ N-equiv. *
ha^-1 yr^-1))

but I don't get what I expect... everything after the first "^" is
considered as a power, whereas I would like to have only the + and the -1 as
a power.

Is there a way to obtain what I want? somehow to split up the expression so
I don't get everything put at the power of NH4.

I already thank you guys for your help!!!

Thomthom

--
View this message in context: http://r.789695.n4.nabble.com/expression-and-axis-labels-tp3672050p3672050.html
Sent from the R help mailing list archive at Nabble.com.
#
On Jul 16, 2011, at 12:09 PM, Thomthom wrote:

            
I have never see a successful concatenation of regular text in quotes  
with expression(...), so my efforts were focussed on making a  
sytactically correct expression:

plot(1~1, xlab=expression(Amount~of~N-fertilizer~kg~NH[4]^"+"*"*"*N- 
equiv.~
ha^-1*yr^-1) )


You need to forget about spaces as separators since they are ignored,   
and use either "~" or "*" as connectives and that also means that if  
you want "*" to appear, it needs to be quoted.

plot(1~1, xlab=expression(Amount~of~N-fertilizer~kg~ NH[4]^ "+" *   
"*"  *  N-equiv.~
ha^-1 * yr^-1) )  # spaces added bak to show grouping, but they are  
still ignored.

I'm guessing you want the last part in parens:

plot(1~1, xlab=expression(Amount~of~N-fertilizer~kg~ NH[4]^ "+" *
                        group("(", list( N-equiv.~ ha^-1 * yr^-1),  
")" ))
#
On Sat, Jul 16, 2011 at 10:10 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
Just a quick addition to David's excellent reply, if you have a lot of
contiguous text and find '~' cumbersome you can also put it all in
quotes:

xn <- expression("Ammount of N-fertilizer kg
"~NH[4]^"+"~~N-equiv.~"*"~ha^-1~yr^-1)
qplot(1:10, 1:10, xlab = xn)

Cheers,

Josh

  
    
#
On 16.07.2011 19:10, David Winsemius wrote:
You can use spaces if you just quote your text, of course:

plot(1~1, xlab = expression("Amount of N-fertilizer kg " * NH[4]^"+" * 
"*" * " N-equiv. " * ha^-1 * yr^-1) )

Best,
Uwe
#
Thanks everyone!

This is exactly what I needed! My graphs look perfect now thanks to you
guys! :)

Thanks so much! I've spent hours on this...

Last question though: do I need to edit my post and signal it as a "solved"
topic (I saw that on other forums... and I have to admit I am not really
familiar with forums ^^)

Have a good one!

Thomthom


--
View this message in context: http://r.789695.n4.nabble.com/expression-and-axis-labels-tp3672050p3672221.html
Sent from the R help mailing list archive at Nabble.com.
#
On 16.07.2011 20:01, Thomthom wrote:
Nor am I: This is not a forum but a mailing list! You probably accessed 
it via an interface that made it look like a forum.
In order to learn how to "behave" in an aoptimal fashion, just read the 
posting guide cited in the footer of each messages to the list.

Best,
Uwe Ligges