how to add a variable to a graph title

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to add a variable to a graph title

JeffND
Hi folks,

To simplify my question, consider an example:

x=runif(1,0,1)
plot(1:5,1:5)

Now I want to add a title to the above plot showing the vaue of x, so if the generated x is 0.3, graphically the tile should be like "Figure 1: x=0.3". How do I achieve this in R?

Thanks.
Jeff
Reply | Threaded
Open this post in threaded view
|

Re: how to add a variable to a graph title

Michael Weylandt
plot(1:5, main = paste0("Figure 1: x=", x))

Michael

On Jul 12, 2012, at 3:30 PM, JeffND <[hidden email]> wrote:

> Hi folks,
>
> To simplify my question, consider an example:
>
> x=runif(1,0,1)
> plot(1:5,1:5)
>
> Now I want to add a title to the above plot showing the vaue of x, so if the
> generated x is 0.3, graphically the tile should be like "Figure 1: x=0.3".
> How do I achieve this in R?
>
> Thanks.
> Jeff
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/how-to-add-a-variable-to-a-graph-title-tp4636364.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to add a variable to a graph title

JeffND
Thank you for this useful code!
Reply | Threaded
Open this post in threaded view
|

Re: how to add a variable to a graph title

mlell08
In reply to this post by Michael Weylandt
To use variables in mathematical expressions, bquote can be used:

#Term in in .( ) is evaluated
plot(1:10,main=bquote(frac(alpha,.(2+2))))


--
GnuPG Key: 0x7340821E

______________________________________________
[hidden email] 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.