[R] Use plotmath expressions read from a text file in mtext/bquote

From: <Paul.Rustomji_at_csiro.au>
Date: Thu, 26 Jun 2008 07:31:56 +1000


Hello R-help List

I am writing some R scripts to create graphs of water quality trends that will be called by a web service running R. The axis titles will need to change as the input data (ie. water quality variable) changes according to a user's choice made via a web page. The way I am currently passing call-specific parameters to the R script is via a text file created on the fly by the web service that is then loaded into a list:

Ie.

>Rscript script1.r par.file.txt

 foo <- commandArgs()
 par.file <- foo[1]

 The parameter text file "par.file.txt" assembed by the web server contains:

222222             #station number
"River at River"   #station name
"ec"               #name of wq variable to be plotted
"EC"~(mu~s/cm)     #axis label (in R plotmath expression) for RHS axis
label

And is read into a list called "ipf" via scan:

ipf.headings <- list(stn=0,stn.name="",wqvar.name="",wqvar.axlab="") ipf <- scan(par.file, ipf.headings,strip.white=T,comment.char="#")

Now, I would like to make a plot with a plotmath expression as the axis title that looks something like this:

plot(1:10)
textstr <- ("EC"~(mu~S/cm))
mtext(bquote(.(textstr)),side=4)

Note that the mu should ideally be the greek character "mu" and EC is electrical conductivity in milli Siemens per centimetre.

The trouble I am having is getting the axis label string (last line of par.file) into R in a way that the mtext/bquote command understands. There seem to be issues around the quoting and perhaps the use of tildes "~" in the plotmath expression.

Any ideas?
Paul

Paul Rustomji
CSIRO Land and Water



R-help_at_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. Received on Wed 25 Jun 2008 - 21:42:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 25 Jun 2008 - 22:31:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive