Re: [R] Help with expression()

2013-10-11 Thread Uwe Ligges

On 10.10.2013 21:40, Sheri wrote:

Hi everyone,

I am hoping someone can help with my attempted use of the expression
function. I have a long series of text and variable to paste together
including a degree symbol. The text is to be placed on my scatter plot
using the mtext function.

Using expression like this:

changetext = expression(paste(Change from ,mini, to , maxi, :,
diff ,degree,C,collapse=))

does not evaluate my user defined variables - mini,maxi, and diff -
just printing them out as words

Using expression like this:

changetext = paste(Change from ,mini, to , maxi, :, diff
,expression(degree,C),collapse=)

prints the text twice and does not evaluate the degree symbol.

I have tried to place the expression alone in a variable and then run the paste:

degsym = expression(degree,C)
changetext = paste(Change from ,mini, to , maxi, :, diff
,degsym,collapse=)

giving me the same result as the second option

Is there any way I can use the expression function as in the first
example but still have R evaluate my user defined variables?

Thanks!
Sheri


I'd rather use substitute for substitution of the symbols and get:



plot(1, main = substitute(Change from  * mini *  to  * maxi * :  * 
diff * degree * C, list(mini=mini, maxi=maxi,diff=diff)))


Best,
Uwe Ligges

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with expression()

2013-10-10 Thread William Dunlap
 changetext = expression(paste(Change from ,mini, to , maxi, :,
 diff ,degree,C,collapse=))
 
 does not evaluate my user defined variables - mini,maxi, and diff -
 just printing them out as words

bquote() can do it: put the variables which should be evaluated in .().  E.g.,
mini - 13
maxi - 97
diff - maxi - mini
plot(0, 0, main=bquote(Change from ~ .(mini) ~ to ~ .(maxi) * : ~ 
.(diff) ~ degree ~ C))

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Sheri O'Connor
 Sent: Thursday, October 10, 2013 1:08 PM
 To: R-help@r-project.org
 Subject: [R] Help with expression()
 
 Hi everyone,
 
 I am hoping someone can help with my attempted use of the expression
 function. I have a long series of text and variable to paste together
 including a degree symbol. The text is to be placed on my scatter plot
 using the mtext function.
 
 Using expression like this:
 
 changetext = expression(paste(Change from ,mini, to , maxi, :,
 diff ,degree,C,collapse=))
 
 does not evaluate my user defined variables - mini,maxi, and diff -
 just printing them out as words
 
 Using expression like this:
 
 changetext = paste(Change from ,mini, to , maxi, :, diff
 ,expression(degree,C),collapse=)
 
 prints the text twice and does not evaluate the degree symbol.
 
 I have tried to place the expression alone in a variable and then run the 
 paste:
 
 degsym = expression(degree,C)
 changetext = paste(Change from ,mini, to , maxi, :, diff
 ,degsym,collapse=)
 
 giving me the same result as the second option
 
 Is there any way I can use the expression function as in the first
 example but still have R evaluate my user defined variables?
 
 Thanks!
 Sheri
 
 ---
 Sheri O'Connor
 M.Sc Candidate
 Department of Biology
 Lakehead University  - Thunder Bay/Orillia
 500 University Avenue
 Orillia, ON L3V 0B9
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with expression()

2013-10-10 Thread Sheri O'Connor
Thanks very much! bquote() did the trick!

on Thu, Oct 10, 2013 at 6:19 PM, William Dunlap wdun...@tibco.com wrote:
 changetext = expression(paste(Change from ,mini, to , maxi, :,
 diff ,degree,C,collapse=))

 does not evaluate my user defined variables - mini,maxi, and diff -
 just printing them out as words

 bquote() can do it: put the variables which should be evaluated in .().  E.g.,
 mini - 13
 maxi - 97
 diff - maxi - mini
 plot(0, 0, main=bquote(Change from ~ .(mini) ~ to ~ .(maxi) * : ~ 
 .(diff) ~ degree ~ C))

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Sheri O'Connor
 Sent: Thursday, October 10, 2013 1:08 PM
 To: R-help@r-project.org
 Subject: [R] Help with expression()

 Hi everyone,

 I am hoping someone can help with my attempted use of the expression
 function. I have a long series of text and variable to paste together
 including a degree symbol. The text is to be placed on my scatter plot
 using the mtext function.

 Using expression like this:

 changetext = expression(paste(Change from ,mini, to , maxi, :,
 diff ,degree,C,collapse=))

 does not evaluate my user defined variables - mini,maxi, and diff -
 just printing them out as words

 Using expression like this:

 changetext = paste(Change from ,mini, to , maxi, :, diff
 ,expression(degree,C),collapse=)

 prints the text twice and does not evaluate the degree symbol.

 I have tried to place the expression alone in a variable and then run the 
 paste:

 degsym = expression(degree,C)
 changetext = paste(Change from ,mini, to , maxi, :, diff
 ,degsym,collapse=)

 giving me the same result as the second option

 Is there any way I can use the expression function as in the first
 example but still have R evaluate my user defined variables?

 Thanks!
 Sheri

 ---
 Sheri O'Connor
 M.Sc Candidate
 Department of Biology
 Lakehead University  - Thunder Bay/Orillia
 500 University Avenue
 Orillia, ON L3V 0B9

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with expression

2012-03-14 Thread ilai
On Wed, Mar 14, 2012 at 8:56 AM, Thomas Hoffmann
hoffm...@giub.uni-bonn.de wrote:
 Hi all,

 I still fail to plot an axis title with the following expression:

 plot(0,xlab=expression('(SOC [' * kgm^{-2} * '])' * ^{-2}))

 the xlab should look like:   (SOC [kgm^2])^0.25

 with an out bracket and a superscript.


Like this ?
plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25,sep='')))


 Thanks for your advice.

 Thomas


        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with expression

2012-03-14 Thread David Winsemius


On Mar 14, 2012, at 11:53 AM, ilai wrote:


On Wed, Mar 14, 2012 at 8:56 AM, Thomas Hoffmann
hoffm...@giub.uni-bonn.de wrote:

Hi all,

I still fail to plot an axis title with the following expression:

plot(0,xlab=expression('(SOC [' * kgm^{-2} * '])' * ^{-2}))

the xlab should look like:   (SOC [kgm^2])^0.25

with an out bracket and a superscript.



Like this ?
plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25,sep='')))


If so, then this is more simple:

plot(0,xlab=expression('(SOC['*kgm^-2*'])'^0.25))  # using * as a  
spaceless connector


And as far as I know, unlike the base R paste function, there is no  
sep argument in the plotmath paste function. Look what happens with:


plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25,sep='#')))

# not used as a separator above, but rather is appended at end

And:

plot(0,xlab=expression(paste('(SOC[',kgm^-2,'])'^0.25))) # no default  
space


--
David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with expression

2011-01-24 Thread Charles C. Berry

On Tue, 25 Jan 2011, David Scott wrote:

I have a problem with expressions. I am trying to create a title where the 
parameter of interest is displayed as a Greek character. Which parameter is 
being considered is stored in a character variable.


As an example, if I have

param - alpha


param - as.name(alpha)


HTH,

Chuck


and then do

plot(0, 0, main = bquote(Parameter==.(param)))

then in the title I get Parameter = alpha,
whereas I want the Greek character alpha.

David Scott


--
_
David Scott Department of Statistics
 The University of Auckland, PB 92019
 Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



Charles C. BerryDept of Family/Preventive Medicine
cbe...@tajo.ucsd.eduUC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with expression

2011-01-24 Thread David Scott

Thanks. Exactly what I wanted.

As usual, I played around with all sorts of things to try and get the 
expression right, but never thought of as.name.


David Scott

On 25/01/2011 4:32 a.m., Charles C. Berry wrote:

On Tue, 25 Jan 2011, David Scott wrote:


I have a problem with expressions. I am trying to create a title where the
parameter of interest is displayed as a Greek character. Which parameter is
being considered is stored in a character variable.

As an example, if I have

param- alpha


param- as.name(alpha)


HTH,

Chuck


and then do

plot(0, 0, main = bquote(Parameter==.(param)))

then in the title I get Parameter = alpha,
whereas I want the Greek character alpha.

David Scott


--
_
David Scott Department of Statistics
 The University of Auckland, PB 92019
 Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



Charles C. BerryDept of Family/Preventive Medicine
cbe...@tajo.ucsd.eduUC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901





--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help in expression( )

2010-06-02 Thread Uwe Ligges



On 02.06.2010 20:22, Shant Ch wrote:



Hi,
I was trying to have a graph whose axes are of the following type:

X axis: n and Y axis: var[U ((a,b) in suffix, and (n,d) in the power)].

U ((a,b) in suffix, and (n,d) in the power)-U^(n,d) _ (a,b).
Actually I require many plots involving different values of a,b,n,d, so need to 
keep this complicated notation.


The code I used:

plot(n, hn$h_pg,  ylab=expression(Var(U[2%,%1]^(n%,%0))-Var(U[1%,%1]^(n%,%0))), 
xlab=n,type=l);



  plot(1, 1, ylab = expression(var(U[list(a,b)]^(list(n,d,
   xlab = n, type = l)

or if you want to replace a, b, d, and n by values, use:

  a - 1
  b - 2
  d - 3
  n - 4

  plot(1, 1, ylab = substitute(var(U[list(a,b)]^(list(n,d))),
   list(a=a, b=b, d=d, n=n)),
   xlab = n, type = l)



The expression() didn't work out for this case. Can anyone help me out.

Also due to the size of the expression in the Y axis, I want to shift the graph 
in the R Graphics window, so that the Y labels are also fully visible. i don't 
know such command which will shift the whole graph a little in the  Graphics 
window.



Define other margins, see argument mar in ?par, e.g.

  par(mar=c(5,5,4,1)+.1)


Uwe Ligges



Thanks, in advance.
Shant




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with expression()

2009-08-18 Thread Kenn Konstabel
All of it is an expression (see ?expression). Maybe you'd better explain
what exactly you're trying to do or what you mean by standard format and
usual way (this part depends very much on what you're used to). You can
manipulate parts of this expression, say, like this:

foo - expression(NA_character_, NA_character_, Null Effect, Pooled
effect,
   NA_character_, NA_character_, NA_character_, NA_character_,
   NA_character_, paste(Het Contours , I^2, sep = ), 0.4,
   0.41, 0.42, 0.45, NA_character_)

foo[[11]] - 1
foo[10] - expression(cat(hello, ppl))

# note that foo[[10]] is a call, so you can manipulate it like the usual
call objects are manipulated (i.e., the standard way :-). foo[10] is an
expression, so you can manipulate it in another standard way.

... and you can convert it to a character vector or a list

as.character(foo)
as.list(foo)

... and you can `eval` the whole expression e.g. using sapply or lapply.

sapply(foo, eval)
# umm ... maybe not, because you refer to I there which is probably in your
global
# environment, so try
sapply(foo, eval, envir=.GlobalEnv)

KK

On Mon, Aug 17, 2009 at 1:24 PM, deanj2k dl...@le.ac.uk wrote:


 Hello.
 I have a vector and within that vector is one expression.  When I display
 this vector it comes up as

 expression(NA_character_, NA_character_, Null Effect, Pooled effect,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, paste(Het Contours , I^2, sep = ), 0.4,
0.41, 0.42, 0.45, NA_character_)

 Where the part in bold is the element which is an expression.  How do I
 change this vector to a standard format what I can manipulate in the usual
 way?


 --
 View this message in context:
 http://www.nabble.com/help-with-expression%28%29-tp25004374p25004374.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with expression()

2009-08-18 Thread Vitalie S.

On Mon, 17 Aug 2009 12:24:28 +0200, deanj2k dl...@le.ac.uk wrote:



Hello.
I have a vector and within that vector is one expression.  When I display
this vector it comes up as

expression(NA_character_, NA_character_, Null Effect, Pooled effect,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, paste(Het Contours , I^2, sep = ), 0.4,
0.41, 0.42, 0.45, NA_character_)

Where the part in bold is the element which is an expression.  How do I
change this vector to a standard format what I can manipulate in the  
usual

way?


Dude, I have no idea what kind of analysis you are mastering, but that  
kind of output does not smell good. Inside the expression you have a  
nested expression, so you have to iterate over.

Here is a way to proceed:

te - expression(NA_character_, NA_character_, Null Effect, Pooled  
effect,

NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, paste(Het Contours , I^2, sep = ), 0.4,
0.41, 0.42, 0.45, NA_character_)


I - 3
tl - lapply(as.list(te), eval, envir=parent.frame())
str(tl)

List of 15
 $ : chr NA
 $ : chr NA
 $ : chr Null Effect
 $ : chr Pooled effect
 $ : chr NA
 $ : chr NA
 $ : chr NA
 $ : chr NA
 $ : chr NA
 $ : chr Het Contours 9
 $ : num 0.4
 $ : num 0.41
 $ : num 0.42
 $ : num 0.45
 $ : chr NA




or if you want unevaluated paste expression just:



as.list(te)

[[1]]
[1] NA

[[2]]
[1] NA

[[3]]
[1] Null Effect

[[4]]
[1] Pooled effect

[[5]]
[1] NA

[[6]]
[1] NA

[[7]]
[1] NA

[[8]]
[1] NA

[[9]]
[1] NA

[[10]]
paste(Het Contours , I^2, sep = )

[[11]]
[1] 0.4

[[12]]
[1] 0.41

[[13]]
[1] 0.42

[[14]]
[1] 0.45

[[15]]
[1] NA





Vitalie.
--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.