revision to expression in a multi-line title...

123 views
Skip to first unread message

adam.l...@pnc.com

unread,
Jun 5, 2013, 5:11:50 PM6/5/13
to ggplot2
Hi again,

I'd sent the question below just moments ago regarding the use of expressions in a title that spans multiple lines. But I realize now that that's the least of my problems.

The particular expression I'm trying to include in my title is rho. But although it works using annotate, it does not show up as expected in the title.
Below is an example:

ggplot(cars,aes(speed,dist))+geom_point()+
        geom_smooth()+
        labs(title=expression(paste("rho==0.081")))+ #does not work
        annotate("text",x=1,y=120,label=paste("rho==0.081"),parse=T) #works


Adam Loveland



----- Forwarded by Adam Loveland/FinAdmin/CLE/PNC on 06/05/2013 05:08 PM -----
From: Adam Loveland/FinAdmin/CLE/PNC
To: ggplot2 <ggp...@googlegroups.com>
Date: 06/05/2013 04:44 PM
Subject: expression in a multi-line title...




Hi all,

The link below shows a solution for a multiple line title that uses an expression. But it was proposed back when "opts" was still in use. Does anyone know if this is still the best approach? Or if theme has made it easier.

https://groups.google.com/forum/#!topicsearchin/ggplot2/expressions$20in$20titles/ggplot2/JVqyio0tvhQ




Adam Loveland

The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any additional advertising or promotional messages from PNC at this e-mail address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp
By unsubscribing to this message, you will be unsubscribed from all advertising or promotional messages from PNC. Removing your e-mail address from this mailing list will not affect your subscription to alerts, e-newsletters or account servicing e-mails.


Ista Zahn

unread,
Jun 5, 2013, 6:23:28 PM6/5/13
to adam.l...@pnc.com, ggplot2
Hi Adam,

plotmath support seems a bit inconsistent in ggplot2, requiring
different methods for different plot elements. I can see some sense in
it (e.g., for geoms you would expect the values to be strings not
expressions, so having a way to convert them makes sense; for plot and
axis titles we can easily construct the expressions ourselves).
Nonetheless, the overall effect is that it seems like a hodgepodge of
methods have to be used depending on what one is trying to do.

Fortunately it is all spelled out for us at
https://github.com/hadley/ggplot2/wiki/Plotmath. For your example you
are just missing the fact that arguments to expression should be
unquoted:

ggplot(cars,aes(speed,dist))+geom_point()+
geom_smooth()+
labs(title=expression(paste(rho==0.081)))+ # works
annotate("text",x=1,y=120,label=paste("rho==0.081"),parse=T) #works

Best,
Ista
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Brian Diggs

unread,
Jun 5, 2013, 6:24:47 PM6/5/13
to adam.lovelan...@public.gmane.org, ggplot2
On 6/5/2013 2:11 PM, adam.lovelan...@public.gmane.org wrote:
> Hi again,
>
> I'd sent the question below just moments ago regarding the use of
> expressions in a title that spans multiple lines. But I realize now that
> that's the least of my problems.
>
> The particular expression I'm trying to include in my title is rho. But
> although it works using annotate, it does not show up as expected in the
> title.
> Below is an example:
>
> ggplot(cars,aes(speed,dist))+geom_point()+
> geom_smooth()+
> labs(title=expression(paste("rho==0.081")))+ #does not work
> annotate("text",x=1,y=120,label=paste("rho==0.081"),parse=T)
> #works

For the title you want

labs(title=expression(rho==0.081))

In the annotation, it is expressed as a string which is then to be
parsed as an expression (what parse=TRUE does). But in a direct
expression, quoted material is literal strings and is not further parsed.

This should get you back to your original problem.

>
> Adam Loveland
>
>
>
> ----- Forwarded by Adam Loveland/FinAdmin/CLE/PNC on 06/05/2013 05:08 PM
> -----
>
> From:
> Adam Loveland/FinAdmin/CLE/PNC
> To:
> ggplot2 <ggplot2-/JYPxA39Uh5...@public.gmane.org>
> Date:
> 06/05/2013 04:44 PM
> Subject:
> expression in a multi-line title...
>
>

> Hi all,
>
> The link below shows a solution for a multiple line title that uses an
> expression. But it was proposed back when "opts" was still in use. Does
> anyone know if this is still the best approach? Or if theme has made it
> easier.
>
> https://groups.google.com/forum/#!topicsearchin/ggplot2/expressions$20in$20titles/ggplot2/JVqyio0tvhQ
>
>
>
>
> Adam Loveland
>
>
>
> The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any additional advertising or promotional messages from PNC at this e-mail address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp
> By unsubscribing to this message, you will be unsubscribed from all advertising or promotional messages from PNC. Removing your e-mail address from this mailing list will not affect your subscription to alerts, e-newsletters or account servicing e-mails.
>
>


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

adam.l...@pnc.com

unread,
Jun 6, 2013, 9:48:57 AM6/6/13
to ggp...@googlegroups.com, Ista Zahn, Brian Diggs, Dennis Murphy
Thanks Ista and Brian for the help. The distinction between geoms and labels and what it means for expressions makes sense now.

And thanks Dennis for the function to display long titles. It will come in handy.


Adam Loveland





From: Ista Zahn <ista...@gmail.com>
To: adam.l...@pnc.com
Cc: ggplot2 <ggp...@googlegroups.com>
Date: 06/05/2013 06:23 PM
Subject: Re: revision to expression in a multi-line title...
Sent by: ggp...@googlegroups.com


Reply all
Reply to author
Forward
0 new messages