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

Paul.Rustomji at csiro.au Paul.Rustomji at csiro.au
Wed Jun 25 23:31:56 CEST 2008

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


>Rscript script1.r par.file.txt

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

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

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

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:

textstr <- ("EC"~(mu~S/cm))

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 Rustomji
CSIRO Land and Water

More information about the R-help mailing list