[R] Transferring commas in character vector to expression

Duncan Mackay mackay at northnet.com.au
Sun Jul 7 00:33:46 CEST 2013

Hi Eric

I have not been following the thread but following on what David has 
said on previous occasions

try for example

plot(1,1, ylab =  expression("aa aaa,aa bb"*Delta*"b cccc"*Delta*"cc, c") )

Below is from a partly saved previous post of David's several months 
ago which may give you some ideas

"A mg kg",
"B mg kg",
"C mg kg",
"D mg kg",
"E mg kg",
"F mg kg",
"G mg kg",
"H mg kg")

pos <- barplot(1:length(DATA_names))
text(x=pos,y=-1, xpd=TRUE, srt=45,
                    labels= sapply( gsub("mg kg", "(mg kg)^-1", DATA_names),



Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

At 07:47 6/07/2013, you wrote:
>I'm trying to format a given character vector as an expression with Greek
>symbols to be used in labeling axis ticks. Thanks to some help from David
>Winsemius, I've learned how to make the substitution and place the Greek
>symbols in, however I've run into another problem: Some of my labels have
>commas in them, so when the parse command is executed, there is an
>unexpected symbol error. For example:
> > x <- c("aa", "aaa,aa", "bb*Delta*b", "cccc*Delta*cc,c")
> > parse(text = x)
>Error in parse(text = x) : <text>:2:4: unexpected ','
>1: aa
>2: aaa,
>      ^
>I've tried various iterations of wrapping the commas in interior quotes
>("aaa\",\"aa"), but then the error shifts to the quote. I see in plotmath
>that 'list(a,b,c)' gives me comma separated values, but I haven't been able
>to work out how to get this construction for elements that have a comma.
>Is this possible?
>Eric Archer, Ph.D.
>Southwest Fisheries Science Center
>8901 La Jolla Shores Drive
>La Jolla, CA 92037 USA
>858-546-7121 (work)
>858-546-7003 (FAX)
>Marine Mammal Genetics Group: swfsc.noaa.gov/prd-mmgenetics
>ETP Cetacean Assessment Program: swfsc.noaa.gov/prd-etp
>"The universe doesn't care what you believe.
>  The wonderful thing about science is that it
>    doesn't ask for your faith, it just asks
>    for your eyes."  - Randall Munroe
>"Lighthouses are more helpful than churches."
>    - Benjamin Franklin
>    "...but I'll take a GPS over either one."
>        - John C. "Craig" George
>         [[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list