[R] Trouble combining plotmath, bquote, expressions
Paul Johnson
pauljohn32 at gmail.com
Wed Apr 2 22:11:02 CEST 2008
I'm using R-2.6.2 on Fedora Linux 9.
I've been experimenting with plotmath.
I wish it were easier to combine expressions in plotmath with values
from the R program itself. There are two parameters in the following
example, the mean "mymean" and standard deviation "mystd". I am able
to use bquote to write elements into the graph title like
mu = mymean
and R will plot the symbol "mu" and the value of mymean from the
program. But I want to combine that result in a string along with
other results.
Can I combine to result like this
"Normal( mu = mymean , sigma = mystd)"
Where symbols mu and sigma are replaced with Greek and mymean and
mystd are drawn from program?
### Filename: Normal1_2008.R
### Paul Johnson March 31, 2008
### This code should be available somewhere in
http://pj.freefaculty.org. If it is not
### email me <pauljohn at ku.edu>
mymean <- 0
mystd <- 1.5
myx <- seq( mymean - 3*mystd, mymean+ 3*mystd, length.out=500)
myDensity <- dnorm(myx,mean=mymean,sd=mystd)
## This works
plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density ",
main=expression(mu == 0))
## This works
plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density ",
main=expression(sigma == 1.5))
## This works
t1 <- bquote( mu== .(mymean))
plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density ", main= t1 )
## This works
t2 <- bquote( sigma== .(mystd))
plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density ", main=t2)
## Can't figure how to combine t1 and t2 into plot title
### This fails!
### plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density
", main=paste( t1,t2) )
plot(myx, myDensity, type="n", xlab="X", ylab="Probability Density ", main= t1 )
## Can drop sigma in as margin text, though, on side 3.
mtext(t2, 3)
lines(myx,myDensity,lty=4, col=4) ### change line type & color if you want
############################
Supposing there is a way to do this, could I submit a working example
to be added to the help page for plotmath ? How could I go about
that?
--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas
More information about the R-help
mailing list