Re: [R] plotmath question
On Fri, 18 Mar 2005, Berton Gunter wrote: 2) The plotmath Help state that expressions can be used for axis labels, so I would have expected the above to work without the eval()call -- but it does not. Would someone kindly explain to me why not -- i.e., what I have misunderstood. That is, to be clear, why does the following not work: Because substitute() doesn't evaluate its argument: the result is not an expression but a call to the expression() function. An example where it is clearer what is going on substitute(log(x),list(x=1)) doesn't return a number, even though log() returns a number. It returns a call to log() that still has to be evaluated -thomas for(i in seq(-3,to=3)) axis(1,at=i, lab=switch(sign(i)+2, substitute(expression(mu-j*sigma),list(j=i)), expression(mu), substitute(expression(mu+j*sigma),list(j=i __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plotmath question
On Friday 18 March 2005 15:41, Berton Gunter wrote: > R listers: > > I have been foiled by plotmath! > > (in R 2.01,Windows 2000) > > The task: Plot a normal density and label the ticks as mu - 3 sigma, mu - 2 > sigma, , mu + 3 sigma, where the mu's and sigmas appear as Greek > symbols, of course. > > The following code does this: > > x<-seq(-3,to=3,by=.01) > y<-dnorm(x) > plot(x,y,type='h',col='lightblue',axes=FALSE) > lines(x,y,col='darkblue') > axis(2) > for(i in seq(-3,to=3)) > axis(1,at=i, lab=switch(sign(i)+2, >eval(substitute(expression(mu-j*sigma),list(j=-i))), >expression(mu), >eval(substitute(expression(mu+j*sigma),list(j=i) > box() > > However, I think the code in the for loop is ugly and probably means that > I'm doing it wrong. In particular: > > 1) Is there a neat way to use one axis() call and a vector (of > expressions?) for the lab=argument? Yes, expression objects can be vectors. e.g.: ## use switch as above for better formatting lab = do.call(expression, lapply(-3:3, function(i) { bquote(mu + .(i) * sigma) } )) axis(1, at = -3:3, lab = lab) > 2) The plotmath Help state that expressions can be used for axis labels, so > I would have expected the above to work without the eval()call -- but it > does not. Would someone kindly explain to me why not -- i.e., what I have > misunderstood. That is, to be clear, why does the following not work: > > for(i in seq(-3,to=3)) > axis(1,at=i, lab=switch(sign(i)+2, >substitute(expression(mu-j*sigma),list(j=i)), >expression(mu), >substitute(expression(mu+j*sigma),list(j=i > is.expression(substitute(expression(mu-j*sigma),list(j=1))) [1] FALSE > is.expression(eval(substitute(expression(mu-j*sigma),list(j=1 [1] TRUE ?substitute says Value: The 'mode' of the result is generally '"call"' ... which evidently have to be evaluated. Hth, Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plotmath question
Bert, This works fine and and seems a little simpler: x<-seq(-3,to=3,by=.01) y<-dnorm(x) plot(x,y,type='h',col='lightblue',axes=FALSE) lines(x,y,col='darkblue') axis(2) ll <- expression(mu-3*sigma, mu-2*sigma, mu-sigma, mu, mu+sigma, mu+2*sigma, mu+3*sigma) axis(1, at=-3:3, lab=ll) box() Cheers, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 Berton Gunter <[EMAIL PROTECTED] ne.com>To Sent by: "'R-help'" [EMAIL PROTECTED] at.math.ethz.chcc Subject 03/18/2005 03:41 [R] plotmath question PM R listers: I have been foiled by plotmath! (in R 2.01,Windows 2000) The task: Plot a normal density and label the ticks as mu - 3 sigma, mu - 2 sigma, , mu + 3 sigma, where the mu's and sigmas appear as Greek symbols, of course. The following code does this: x<-seq(-3,to=3,by=.01) y<-dnorm(x) plot(x,y,type='h',col='lightblue',axes=FALSE) lines(x,y,col='darkblue') axis(2) for(i in seq(-3,to=3)) axis(1,at=i, lab=switch(sign(i)+2, eval(substitute(expression(mu-j*sigma),list(j=-i))), expression(mu), eval(substitute(expression(mu+j*sigma),list(j=i) box() However, I think the code in the for loop is ugly and probably means that I'm doing it wrong. In particular: 1) Is there a neat way to use one axis() call and a vector (of expressions?) for the lab=argument? 2) The plotmath Help state that expressions can be used for axis labels, so I would have expected the above to work without the eval()call -- but it does not. Would someone kindly explain to me why not -- i.e., what I have misunderstood. That is, to be clear, why does the following not work: for(i in seq(-3,to=3)) axis(1,at=i, lab=switch(sign(i)+2, substitute(expression(mu-j*sigma),list(j=i)), expression(mu), substitute(expression(mu+j*sigma),list(j=i Any further ideas,insights, or pointers to reference materials would also be appreciated. Many thanks. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] plotmath question
R listers: I have been foiled by plotmath! (in R 2.01,Windows 2000) The task: Plot a normal density and label the ticks as mu - 3 sigma, mu - 2 sigma, , mu + 3 sigma, where the mu's and sigmas appear as Greek symbols, of course. The following code does this: x<-seq(-3,to=3,by=.01) y<-dnorm(x) plot(x,y,type='h',col='lightblue',axes=FALSE) lines(x,y,col='darkblue') axis(2) for(i in seq(-3,to=3)) axis(1,at=i, lab=switch(sign(i)+2, eval(substitute(expression(mu-j*sigma),list(j=-i))), expression(mu), eval(substitute(expression(mu+j*sigma),list(j=i) box() However, I think the code in the for loop is ugly and probably means that I'm doing it wrong. In particular: 1) Is there a neat way to use one axis() call and a vector (of expressions?) for the lab=argument? 2) The plotmath Help state that expressions can be used for axis labels, so I would have expected the above to work without the eval()call -- but it does not. Would someone kindly explain to me why not -- i.e., what I have misunderstood. That is, to be clear, why does the following not work: for(i in seq(-3,to=3)) axis(1,at=i, lab=switch(sign(i)+2, substitute(expression(mu-j*sigma),list(j=i)), expression(mu), substitute(expression(mu+j*sigma),list(j=i Any further ideas,insights, or pointers to reference materials would also be appreciated. Many thanks. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plotmath question: y'
"Pascal A. Niklaus" <[EMAIL PROTECTED]> writes: > Hi all, > > I wonder how to correctly write the following expression (it's the > axis label in a plot command): > > ylab=expression(y' == y - bar(y) ) > > Somehow the single quote in y' is causing the problems, I guess > because it is interpreted as a quote... > Does it have to be escaped? But how? y*minute or y*"'" should do it. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] plotmath question: y'
Pascal A. Niklaus wrote: Hi all, I wonder how to correctly write the following expression (it's the axis label in a plot command): ylab=expression(y' == y - bar(y) ) expression(y * "'" == y - bar(y)) Uwe Ligges Somehow the single quote in y' is causing the problems, I guess because it is interpreted as a quote... Does it have to be escaped? But how? Thanks for your help Pascal __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] plotmath question: y'
Hi all, I wonder how to correctly write the following expression (it's the axis label in a plot command): ylab=expression(y' == y - bar(y) ) Somehow the single quote in y' is causing the problems, I guess because it is interpreted as a quote... Does it have to be escaped? But how? Thanks for your help Pascal __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help