On Aug 1, 2010, at 11:03 AM, Dennis Fisher wrote:
Colleagues,
I am encountering difficulty adding formatted text to a graphic.
Specifically, I want to add a superscript in the middle of a text
string but I would like to format the text string on the fly. The
commands:
plot(1,1)
ARG <- bquote('TEXT'^'\u00ae')
mtext(ARG, line=-2, side=1)
yield the desired output.
However, my goal is to paste together a string, then pass it to
mtext. For example:
plot(1,1)
PART1 <- 'TEXT'
PART2 <- '^'
PART3 <- '\u00ae'
ARG <- paste(PART1, PART2, PART3)
mtext(bquote(.(ARG)), line=-2, side=1) ## bquote(ARG) also does
not work
This does not work -- the unprocessed string:
TEXT ^ ®
is printed.
Obviously, I don't understand some aspect of passing arguments to
bquote. Of note, I tried "expression" instead of bquote but I was
not able to get the registered sign ('\u00ae') to appear as a
superscript.
I'm would be embarrassed to state the number of failed attempts I made
with substitute, expression,, as.expression and parse before eventual
success, but here's what finally "worked".
plot(1,1);
mtext(bquote(.(PART1)^.(PART3)), line=-2, side=1)
I think trying to substitute for "^" will require a different
approach, since sticking a series of .() calls seems to be
unacceptable to the interpreter :
## "Does not work"
plot(1,1);
mtext(bquote(.(PART1).(PART2).(PART3)), line=-2, side=1)
#Error: unexpected symbol in " mtext(bquote(.(PART1)."
Any help would be appreciated.
Dennis
(R 2.11; OS X [platform should not be an issue here])
I cannot assess, since that is also my platform.
--
David Winsemius, MD
West Hartford, CT
______________________________________________
R-help@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.