[R] expression() and axis labels
jwiley.psych at gmail.com
Sat Jul 16 19:22:02 CEST 2011
On Sat, Jul 16, 2011 at 10:10 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
> On Jul 16, 2011, at 12:09 PM, Thomthom wrote:
>> 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^+ N-equiv. *
>> ha^-1 yr^-1))
> 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^"+"*"*"*N-equiv.~
> ha^-1*yr^-1) )
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
xn <- expression("Ammount of N-fertilizer kg
qplot(1:10, 1:10, xlab = xn)
> 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^ "+" * "*" *
> ha^-1 * yr^-1) ) # spaces added bak to show grouping, but they are still
> I'm guessing you want the last part in parens:
> plot(1~1, xlab=expression(Amount~of~N-fertilizer~kg~ NH^ "+" *
> group("(", list( 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
>> a power.
>> Is there a way to obtain what I want? somehow to split up the expression
>> I don't get everything put at the power of NH4.
>> I already thank you guys for your help!!!
>> View this message in context:
>> Sent from the R help mailing list archive at Nabble.com.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
> David Winsemius, MD
> West Hartford, CT
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
University of California, Los Angeles
More information about the R-help