Plot math symbol with string and number

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Plot math symbol with string and number

John Smith-5
Dear Helpers,

I would like to make plots with titles for different data sets and
different parameters. So a useful title should combine data name
and parameter for clarity. The following is a simplified code example with
two plots. The first title doesn't show sigma as a math symbol, while the
second one doesn't contain the s value as a numeric value - I could
manually change the s value, but when there are many different s values,
this is not a good solution. Thanks!

s <- 1
y <- rnorm(100)
plot(y, main=paste("data", "sigma=", s))
plot(y, main=expression(paste("data", sigma,"=", s)))

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Bert Gunter-2
?plotmath

On Sun, Aug 16, 2020, 14:53 John Smith <[hidden email]> wrote:

> Dear Helpers,
>
> I would like to make plots with titles for different data sets and
> different parameters. So a useful title should combine data name
> and parameter for clarity. The following is a simplified code example with
> two plots. The first title doesn't show sigma as a math symbol, while the
> second one doesn't contain the s value as a numeric value - I could
> manually change the s value, but when there are many different s values,
> this is not a good solution. Thanks!
>
> s <- 1
> y <- rnorm(100)
> plot(y, main=paste("data", "sigma=", s))
> plot(y, main=expression(paste("data", sigma,"=", s)))
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Bert Gunter-2
Specifically, see the "how to combine "math" and numeric variables" in the
Examples therein.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Aug 16, 2020 at 3:18 PM Bert Gunter <[hidden email]> wrote:

> ?plotmath
>
> On Sun, Aug 16, 2020, 14:53 John Smith <[hidden email]> wrote:
>
>> Dear Helpers,
>>
>> I would like to make plots with titles for different data sets and
>> different parameters. So a useful title should combine data name
>> and parameter for clarity. The following is a simplified code example with
>> two plots. The first title doesn't show sigma as a math symbol, while the
>> second one doesn't contain the s value as a numeric value - I could
>> manually change the s value, but when there are many different s values,
>> this is not a good solution. Thanks!
>>
>> s <- 1
>> y <- rnorm(100)
>> plot(y, main=paste("data", "sigma=", s))
>> plot(y, main=expression(paste("data", sigma,"=", s)))
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Rasmus Liland-3
On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| On Sun, Aug 16, 2020, 14:53 John wrote:
| |
| | I would like to make plots with
| | titles for different data sets and
| | different parameters. The first
| | title doesn't show sigma as a math
| | symbol, while the second one
| | doesn't contain the s value as a
| | numeric value
| |
| | s <- 1
| | y <- rnorm(100)
| | plot(y, main=paste("data", "sigma=", s))
| | plot(y, main=expression(paste("data", sigma,"=", s)))
|
| ?plotmath

Dear John, read ?plotmath, it is good, I
was not aware of its existence; then
backquote s like so:

        plot(y, main=bquote(paste(
          "data" ~~ widehat(aleph)
          %notin% .(s)^.(s))))

V

r

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

John Smith-5
Thanks to Dunkan, Rasmus and Bert. Will keep the very useful tips. Best!

On Sun, Aug 16, 2020 at 9:13 PM Rasmus Liland <[hidden email]> wrote:

> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> | On Sun, Aug 16, 2020, 14:53 John wrote:
> | |
> | | I would like to make plots with
> | | titles for different data sets and
> | | different parameters. The first
> | | title doesn't show sigma as a math
> | | symbol, while the second one
> | | doesn't contain the s value as a
> | | numeric value
> | |
> | | s <- 1
> | | y <- rnorm(100)
> | | plot(y, main=paste("data", "sigma=", s))
> | | plot(y, main=expression(paste("data", sigma,"=", s)))
> |
> | ?plotmath
>
> Dear John, read ?plotmath, it is good, I
> was not aware of its existence; then
> backquote s like so:
>
>         plot(y, main=bquote(paste(
>           "data" ~~ widehat(aleph)
>           %notin% .(s)^.(s))))
>
> V
>
> r
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: [EXT] Re: Plot math symbol with string and number

dkStevens
John - one more approach

plot(y,main=parse(text=paste0('data ~~ sigma == ',s)))

Good luck

David Stevens

On 8/17/2020 8:23 AM, John Smith wrote:

> Thanks to Dunkan, Rasmus and Bert. Will keep the very useful tips. Best!
>
> On Sun, Aug 16, 2020 at 9:13 PM Rasmus Liland <[hidden email]> wrote:
>
>> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
>> | On Sun, Aug 16, 2020, 14:53 John wrote:
>> | |
>> | | I would like to make plots with
>> | | titles for different data sets and
>> | | different parameters. The first
>> | | title doesn't show sigma as a math
>> | | symbol, while the second one
>> | | doesn't contain the s value as a
>> | | numeric value
>> | |
>> | | s <- 1
>> | | y <- rnorm(100)
>> | | plot(y, main=paste("data", "sigma=", s))
>> | | plot(y, main=expression(paste("data", sigma,"=", s)))
>> |
>> | ?plotmath
>>
>> Dear John, read ?plotmath, it is good, I
>> was not aware of its existence; then
>> backquote s like so:
>>
>>          plot(y, main=bquote(paste(
>>            "data" ~~ widehat(aleph)
>>            %notin% .(s)^.(s))))
>>
>> V
>>
>> r
>>
>          [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
> CAUTION: This email originated from outside of USU. If this appears to be a USU employee, beware of impersonators. Do not click links, reply, download images, or open attachments unless you verify the sender’s identity and know the content is safe.
>
--
David K Stevens, P.E., Ph.D.
Professor, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
[hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: [EXT] Re: Plot math symbol with string and number

John Smith-5
Thanks David for a quite interesting suggestion: Indeed I didn't know
paste0! Best!

On Mon, Aug 17, 2020 at 12:26 PM David K Stevens <[hidden email]>
wrote:

> John - one more approach
>
> plot(y,main=parse(text=paste0('data ~~ sigma == ',s)))
>
> Good luck
>
> David Stevens
>
> On 8/17/2020 8:23 AM, John Smith wrote:
> > Thanks to Dunkan, Rasmus and Bert. Will keep the very useful tips. Best!
> >
> > On Sun, Aug 16, 2020 at 9:13 PM Rasmus Liland <[hidden email]> wrote:
> >
> >> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> >> | On Sun, Aug 16, 2020, 14:53 John wrote:
> >> | |
> >> | | I would like to make plots with
> >> | | titles for different data sets and
> >> | | different parameters. The first
> >> | | title doesn't show sigma as a math
> >> | | symbol, while the second one
> >> | | doesn't contain the s value as a
> >> | | numeric value
> >> | |
> >> | | s <- 1
> >> | | y <- rnorm(100)
> >> | | plot(y, main=paste("data", "sigma=", s))
> >> | | plot(y, main=expression(paste("data", sigma,"=", s)))
> >> |
> >> | ?plotmath
> >>
> >> Dear John, read ?plotmath, it is good, I
> >> was not aware of its existence; then
> >> backquote s like so:
> >>
> >>          plot(y, main=bquote(paste(
> >>            "data" ~~ widehat(aleph)
> >>            %notin% .(s)^.(s))))
> >>
> >> V
> >>
> >> r
> >>
> >          [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > 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.
> > CAUTION: This email originated from outside of USU. If this appears to
> be a USU employee, beware of impersonators. Do not click links, reply,
> download images, or open attachments unless you verify the sender’s
> identity and know the content is safe.
> >
> --
> David K Stevens, P.E., Ph.D.
> Professor, Environmental Engineering
> Civil and Environmental Engineering
> Utah Water Research Laboratory
> 8200 Old Main Hill
> Logan, UT  84322-8200
> 435 797 3229 - voice
> 435 797 1363 - fax
> [hidden email]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

cpolwart-2
In reply to this post by Rasmus Liland-3
On 2020-08-17 03:13, Rasmus Liland wrote:

> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> | On Sun, Aug 16, 2020, 14:53 John wrote:
> | |
> | | I would like to make plots with
> | | titles for different data sets and
> | | different parameters. The first
> | | title doesn't show sigma as a math
> | | symbol, while the second one
> | | doesn't contain the s value as a
> | | numeric value
> | |
> | | s <- 1
> | | y <- rnorm(100)
> | | plot(y, main=paste("data", "sigma=", s))
> | | plot(y, main=expression(paste("data", sigma,"=", s)))
> |
> | ?plotmath
>
> Dear John, read ?plotmath, it is good, I
> was not aware of its existence; then
> backquote s like so:
>
>

Plotmath seems to be the right way to do it.  But without reading
plotmath I'd have gone with this:

plot(y, main=paste("data", "\u03C3=", s))

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Rasmus Liland-3
On 2020-08-17 22:14 +0100, [hidden email] wrote:
| On 2020-08-17 03:13, Rasmus Liland wrote:
| | On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
| | |
| | | ?plotmath
| |
| | Dear John, read ?plotmath, it is
| | good, I was not aware of its
| | existence; then backquote s like
| | so:
|
| Plotmath seems to be the right way to
| do it.  But without reading plotmath
| I'd have gone with this:
|
| plot(y, main=paste("data", "\u03C3=", s))

Good; for me copying the sigma unicode
character into that line works too:

        plot(y, main=paste("dataσ=", s))

How curious

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Bert Gunter-2
In reply to this post by cpolwart-2
"Plotmath seems to be the right way to do it. "

Not sure I agree with that. Paul Murrell put together plotmath around 2000
prior to the widescale development and adoption of the unicode standard
(corrections/modifications welcome!).  So at the time, there really was no
other way to handle this for most OS'es. With UTF8 now being generally
supported for Unicode, plotmath constructions may not be needed for simple
symbol labeling, as here. Of course for more complex symbolism (fractions,
integrals, ...) it will be. ?plotmath talks about this and has links to
further issues and options, btw.

In other words, unicode may indeed be better than my suggestion of plotmath
here.

I would welcome comments from others who are more knowledgeable about this
than I am.

Bert

On Mon, Aug 17, 2020 at 2:14 PM <[hidden email]> wrote:

> On 2020-08-17 03:13, Rasmus Liland wrote:
> > On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
> > | On Sun, Aug 16, 2020, 14:53 John wrote:
> > | |
> > | | I would like to make plots with
> > | | titles for different data sets and
> > | | different parameters. The first
> > | | title doesn't show sigma as a math
> > | | symbol, while the second one
> > | | doesn't contain the s value as a
> > | | numeric value
> > | |
> > | | s <- 1
> > | | y <- rnorm(100)
> > | | plot(y, main=paste("data", "sigma=", s))
> > | | plot(y, main=expression(paste("data", sigma,"=", s)))
> > |
> > | ?plotmath
> >
> > Dear John, read ?plotmath, it is good, I
> > was not aware of its existence; then
> > backquote s like so:
> >
> >
>
> Plotmath seems to be the right way to do it.  But without reading
> plotmath I'd have gone with this:
>
> plot(y, main=paste("data", "\u03C3=", s))
>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Paul Murrell-2

I think that comment is fair *on graphics devices that can handle unicode*.

So that is true for Cairo-based graphics devices, but not for the pdf()
or postscript() devices, for example.

Paul

On 18/08/20 9:54 am, Bert Gunter wrote:

> "Plotmath seems to be the right way to do it."
>
> Not sure I agree with that. Paul Murrell put together plotmath around 2000
> prior to the widescale development and adoption of the unicode standard
> (corrections/modifications welcome!).  So at the time, there really was no
> other way to handle this for most OS'es. With UTF8 now being generally
> supported for Unicode, plotmath constructions may not be needed for simple
> symbol labeling, as here. Of course for more complex symbolism (fractions,
> integrals, ...) it will be. ?plotmath talks about this and has links to
> further issues and options, btw.
>
> In other words, unicode may indeed be better than my suggestion of plotmath
> here.
>
> I would welcome comments from others who are more knowledgeable about this
> than I am.
>
> Bert
>
> On Mon, Aug 17, 2020 at 2:14 PM <[hidden email]> wrote:
>
>> On 2020-08-17 03:13, Rasmus Liland wrote:
>>> On Sun, Aug 16, 2020 at 3:18 PM Bert wrote:
>>> | On Sun, Aug 16, 2020, 14:53 John wrote:
>>> | |
>>> | | I would like to make plots with
>>> | | titles for different data sets and
>>> | | different parameters. The first
>>> | | title doesn't show sigma as a math
>>> | | symbol, while the second one
>>> | | doesn't contain the s value as a
>>> | | numeric value
>>> | |
>>> | | s <- 1
>>> | | y <- rnorm(100)
>>> | | plot(y, main=paste("data", "sigma=", s))
>>> | | plot(y, main=expression(paste("data", sigma,"=", s)))
>>> |
>>> | ?plotmath
>>>
>>> Dear John, read ?plotmath, it is good, I
>>> was not aware of its existence; then
>>> backquote s like so:
>>>
>>>
>>
>> Plotmath seems to be the right way to do it.  But without reading
>> plotmath I'd have gone with this:
>>
>> plot(y, main=paste("data", "\u03C3=", s))
>>
>>
>>
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&amp;data=02%7C01%7C%7C3624d54caaf64787734308d842f83677%7Cd1b36e950d5042e9958fb63fa906beaa%7C0%7C0%7C637332981200092221&amp;sdata=U7ywrEh7Z3XV84pkxXfzUJTYU8BEZ995Np5xo3%2Fbn9g%3D&amp;reserved=0
> PLEASE do read the posting guide https://apc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&amp;data=02%7C01%7C%7C3624d54caaf64787734308d842f83677%7Cd1b36e950d5042e9958fb63fa906beaa%7C0%7C0%7C637332981200092221&amp;sdata=7VBd7dQFox%2BCEUEKgJZk6TU6cwmDS7tnAcGok9UH1WQ%3D&amp;reserved=0
> and provide commented, minimal, self-contained, reproducible code.
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Plot math symbol with string and number

Rasmus Liland-3
On 2020-08-18 11:02 +1200, Paul Murrell wrote:
| On 18/08/20 9:54 am, Bert Gunter wrote:
| | On Mon, Aug 17, 2020 at 2:14 PM <[hidden email]> wrote:
| | |
| | | Plotmath seems to be the right way
| | | to do it.  But without reading
| | | plotmath I'd have gone with this:
| | |
| | | plot(y, main=paste("data", "\u03C3=", s))
| |
| | "Plotmath seems to be the right way
| | to do it."
| |
| | Not sure I agree with that. Paul
| | Murrell put together plotmath around
| | 2000 prior to the widescale
| | development and adoption of the
| | unicode standard
| | (corrections/modifications
| | welcome!).  So at the time, there
| | really was no other way to handle
| | this for most OS'es. With UTF8 now
| | being generally supported for
| | Unicode, plotmath constructions may
| | not be needed for simple symbol
| | labeling, as here. Of course for
| | more complex symbolism (fractions,
| | integrals, ...) it will be.
| | ?plotmath talks about this and has
| | links to further issues and options,
| | btw.
| |
| | In other words, unicode may indeed
| | be better than my suggestion of
| | plotmath here.
|
| I think that comment is fair *on
| graphics devices that can handle
| unicode*.
|
| So that is true for Cairo-based
| graphics devices, but not for the
| pdf() or postscript() devices, for
| example.

Eventhough I'm a heavy user of pdf(), I
didn't notice at first that the sigma
gets converted to two dots with the
error messages

        Warning messages:
        1: In title(...) :
          conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted for <cf>
        2: In title(...) :
          conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted for <83>
        3: In title(...) :
          conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted for <cf>
        4: In title(...) :
          conversion failure on 'data σ= 1' in 'mbcsToSbcs': dot substituted for <83>

like if it was a Han character (most
likely three dots in that case), I just
ran with cpolwart's suggestion in
whatever is the default on the R
console, probably that Cairo thing.  
png() works ofc.

V

r

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

signature.asc (849 bytes) Download Attachment