I would like to insert a superscript in a body of text (e.g., a title or
axis label), where the superscript is not necessarily at the end of the
text. For example, suppose a title read, "This is a Test^1 of the
Emergency Broadcast System" where there is a superscript 1 after the word
Test.
As a starting point for what I'm trying to do, the following shows a
superscript:
x=10
plot(x)
text(x=1, y=12, expression("test"^1)
But, the following does not show a superscript:
x=10
plot(x)
text(x=1, y=11, paste("This is a", expression("test"^1), "of the Emergency
Broadcast System.")
Thanks in advance to all those who reply.
Best,
Brian Kriegler
bkriegler39 at gmail.com
--
Inserting superscripts in free-format text line
8 messages · Brian Kriegler, David Winsemius, William Dunlap +1 more
On Aug 20, 2012, at 11:35 AM, Brian Kriegler wrote:
I would like to insert a superscript in a body of text (e.g., a
title or axis label), where the superscript is not necessarily at
the end of the text. For example, suppose a title read, "This is a
Test^1 of the Emergency Broadcast System" where there is a
superscript 1 after the word Test.
As a starting point for what I'm trying to do, the following shows a
superscript:
x=10
plot(x)
text(x=1, y=12, expression("test"^1)
Not on my device. No closing paren. Why not: plot(1:10) text(x=5, y=4.5, expression(test^1) ) You do not need quotes in plotmath expressions unless they are reserved plotmath function names. People reach for paste() in far too many situations.
But, the following does not show a superscript:
x=10
plot(x)
text(x=1, y=11, paste("This is a", expression("test"^1), "of the
Emergency Broadcast System.")
And why not: expression(This~is~a~test^1~of~the~Emergency~Broadcast~System.)
David Winsemius, MD Alameda, CA, USA
paste() is ok, but it must be enclosed in expression(),
just like the case that worked.
plot(-15:15,15:-15)
text(x=5, y=4.5, expression(test^1) )
text(x=1, y=11, expression(paste("This is a ", test^1, " of the Emergency Broadcast System.")))
plotmath only works on expressions, not on the strings
that a call to paste would produce.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius Sent: Monday, August 20, 2012 12:15 PM To: Brian Kriegler Cc: r-help at r-project.org Subject: Re: [R] Inserting superscripts in free-format text line On Aug 20, 2012, at 11:35 AM, Brian Kriegler wrote:
I would like to insert a superscript in a body of text (e.g., a
title or axis label), where the superscript is not necessarily at
the end of the text. For example, suppose a title read, "This is a
Test^1 of the Emergency Broadcast System" where there is a
superscript 1 after the word Test.
As a starting point for what I'm trying to do, the following shows a
superscript:
x=10
plot(x)
text(x=1, y=12, expression("test"^1)
Not on my device. No closing paren. Why not: plot(1:10) text(x=5, y=4.5, expression(test^1) ) You do not need quotes in plotmath expressions unless they are reserved plotmath function names. People reach for paste() in far too many situations.
But, the following does not show a superscript:
x=10
plot(x)
text(x=1, y=11, paste("This is a", expression("test"^1), "of the
Emergency Broadcast System.")
And why not: expression(This~is~a~test^1~of~the~Emergency~Broadcast~System.)
-- David Winsemius, MD Alameda, CA, USA
______________________________________________ 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.
On 2012-08-20 12:27, William Dunlap wrote:
paste() is ok, but it must be enclosed in expression(),
just like the case that worked.
plot(-15:15,15:-15)
text(x=5, y=4.5, expression(test^1) )
text(x=1, y=11, expression(paste("This is a ", test^1, " of the Emergency Broadcast System.")))
plotmath only works on expressions, not on the strings
that a call to paste would produce.
It's a matter of paste, of course (whoops, I mean a matter of _t_aste),
but I agree with David that, in plotmath situations, paste() is often
not the best way to proceed, especially in view of the fact that
plotmath's paste() doesn't recognize the 'sep=' argument; this often
confounds useRs.
In the above, example, I would prefer to use concatenation of the
string pieces with either '~' (a space) or '*` (no space):
text(x=1, y=11, expression("This is a" ~ test^1 ~ "of the
Emergency Broadcast System."))
or
text(x=1, y=11, expression("This is a " * test^1 * " of the
Emergency Broadcast System."))
If one is going to use plotmath expressions frequently, then these
two handy little symbols are worth knowing.
Peter Ehlers
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius Sent: Monday, August 20, 2012 12:15 PM To: Brian Kriegler Cc: r-help at r-project.org Subject: Re: [R] Inserting superscripts in free-format text line On Aug 20, 2012, at 11:35 AM, Brian Kriegler wrote:
I would like to insert a superscript in a body of text (e.g., a
title or axis label), where the superscript is not necessarily at
the end of the text. For example, suppose a title read, "This is a
Test^1 of the Emergency Broadcast System" where there is a
superscript 1 after the word Test.
As a starting point for what I'm trying to do, the following shows a
superscript:
x=10
plot(x)
text(x=1, y=12, expression("test"^1)
Not on my device. No closing paren. Why not: plot(1:10) text(x=5, y=4.5, expression(test^1) ) You do not need quotes in plotmath expressions unless they are reserved plotmath function names. People reach for paste() in far too many situations.
But, the following does not show a superscript:
x=10
plot(x)
text(x=1, y=11, paste("This is a", expression("test"^1), "of the
Emergency Broadcast System.")
And why not: expression(This~is~a~test^1~of~the~Emergency~Broadcast~System.)
-- David Winsemius, MD Alameda, CA, USA
______________________________________________ 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.
______________________________________________ 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.
Thanks. These are all extremely helpful suggestions and much appreciated. On Mon, 20 Aug 2012 14:30:05 -0700, Peter Ehlers <ehlers at ucalgary.ca> wrote:
On 2012-08-20 12:27, William Dunlap wrote:
paste() is ok, but it must be enclosed in expression(),
just like the case that worked.
plot(-15:15,15:-15)
text(x=5, y=4.5, expression(test^1) )
text(x=1, y=11, expression(paste("This is a ", test^1, " of the
Emergency Broadcast System.")))
plotmath only works on expressions, not on the strings
that a call to paste would produce.
It's a matter of paste, of course (whoops, I mean a matter of _t_aste),
but I agree with David that, in plotmath situations, paste() is often
not the best way to proceed, especially in view of the fact that
plotmath's paste() doesn't recognize the 'sep=' argument; this often
confounds useRs.
In the above, example, I would prefer to use concatenation of the
string pieces with either '~' (a space) or '*` (no space):
text(x=1, y=11, expression("This is a" ~ test^1 ~ "of the
Emergency Broadcast System."))
or
text(x=1, y=11, expression("This is a " * test^1 * " of the
Emergency Broadcast System."))
If one is going to use plotmath expressions frequently, then these
two handy little symbols are worth knowing.
Peter Ehlers
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of David Winsemius Sent: Monday, August 20, 2012 12:15 PM To: Brian Kriegler Cc: r-help at r-project.org Subject: Re: [R] Inserting superscripts in free-format text line On Aug 20, 2012, at 11:35 AM, Brian Kriegler wrote:
I would like to insert a superscript in a body of text (e.g., a
title or axis label), where the superscript is not necessarily at
the end of the text. For example, suppose a title read, "This is a
Test^1 of the Emergency Broadcast System" where there is a
superscript 1 after the word Test.
As a starting point for what I'm trying to do, the following shows a
superscript:
x=10
plot(x)
text(x=1, y=12, expression("test"^1)
Not on my device. No closing paren. Why not: plot(1:10) text(x=5, y=4.5, expression(test^1) ) You do not need quotes in plotmath expressions unless they are reserved plotmath function names. People reach for paste() in far too many situations.
But, the following does not show a superscript:
x=10
plot(x)
text(x=1, y=11, paste("This is a", expression("test"^1), "of the
Emergency Broadcast System.")
And why not: expression(This~is~a~test^1~of~the~Emergency~Broadcast~System.)
-- David Winsemius, MD Alameda, CA, USA
______________________________________________ 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.
______________________________________________ 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.
--
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120821/08ddc50d/attachment.pl>
On 2012-08-21 08:28, Brian Kriegler wrote:
All of these suggestions are great. Let me add one other dimension.
Suppose I want to add curly quotations, italicize, underline, or bold
some of the words. I can get this to work:
plot(-15:15,15:-15, pch=NA)
text(x=0, y=5,
expression(bold(This)~is~a~underline(test)^1~of~the~italic(Emergency)~Broadcast~System.))
I can also get this to work:
text(x=0, y=-5, dQuote("This is another test."))
But, I've wrestled getting curly quotes to work within expression().
Any suggestions are greatly appreciated.
-Brian
[....] Font issues can be system-dependent. The following works for me on Windows. Insert unicode characters in the appropriate places. For example, to place double quotes around the word 'Broadcast' in your example above: text(0, 5, expression(....~"\u201c"*Broadcast*"\u201d"~System)) Don't forget the '*' to concatenate the quote symbols with the word. Peter Ehlers
On Aug 21, 2012, at 10:39 AM, Peter Ehlers wrote:
On 2012-08-21 08:28, Brian Kriegler wrote:
All of these suggestions are great. Let me add one other dimension.
Suppose I want to add curly quotations, italicize, underline, or
bold
some of the words. I can get this to work:
plot(-15:15,15:-15, pch=NA)
text(x=0, y=5,
expression
(bold
(This
)~is~a~underline(test)^1~of~the~italic(Emergency)~Broadcast~System.))
I can also get this to work:
text(x=0, y=-5, dQuote("This is another test."))
But, I've wrestled getting curly quotes to work within expression().
Any suggestions are greatly appreciated.
-Brian
[....] Font issues can be system-dependent. The following works for me on Windows. Insert unicode characters in the appropriate places. For example, to place double quotes around the word 'Broadcast' in your example above: text(0, 5, expression(....~"\u201c"*Broadcast*"\u201d"~System))
This would be a way to make that expression somewhat more "symbolic" by defining the special characters outside the expression and then using the bquote and .() functions: qql <- "\u201c" qqr <- "\u201d" plot(0:10,0:10) text(5, 5.5, bquote(Emergency~ .(qql)*Broadcast*.(qqr)~System)) That's nice because it opens up the possibilty of accessing other object values as well.
Don't forget the '*' to concatenate the quote symbols with the word. Peter Ehlers
David Winsemius, MD Alameda, CA, USA