What I want to do is put the arguments I supply to a function into the title of a plot Say I'm calling func.1 func.1(a=4,b=4) plot(....,..., title("a=4, b=4")) If I'm calling func.1 with different arguments, I want the plot title to reflect that. A small detail is that func.1 might have an argument with a default like c=a+b. I tried using expression but couldn't get it to work. Is there a way to do this using expression() ? -- Sancar Adali [[alternative HTML version deleted]]
Try this:> LinePlot(1,1) > LinePlot=function(a,b){+ # a = slope + # b = y intercept + x=seq(-10,10,0.4) + y=a*x+b + plot(x,y, type="l") + title(paste("a=",a,"b=",b)) + }> > #test > LinePlot(a=-2,b=9)HTH -- View this message in context: http://r.789695.n4.nabble.com/expression-and-plot-title-tp2348566p2350361.html Sent from the R help mailing list archive at Nabble.com.
On Aug 28, 2010, at 12:53 AM, Sancar Adali wrote:> What I want to do is put the arguments I supply to a function into > the > title of a plot > Say I'm calling func.1 > func.1(a=4,b=4) > plot(....,..., title("a=4, b=4"))> If I'm calling func.1 with different arguments, I want the plot > title to > reflect that. > A small detail is that func.1 might have an argument with a default > like > c=a+b.Need a code example.> I tried using expression but couldn't get it to work.You should be using bquote.> > Is there a way to do this using expression() ?Refer to the answers given earlier today. Subject line: "How to plot an expression-label with variable text" -- David.
Here is a suggestion you may care to develop func <- function(a, b) { plot(1:10) title(main = bquote(a == .(a)*','~ b == .(b))) invisible() } try with func(1,2) func(36, 2^10) &c -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Sancar Adali Sent: Saturday, 28 August 2010 2:54 PM To: r-help Subject: [R] expression() and plot title What I want to do is put the arguments I supply to a function into the title of a plot Say I'm calling func.1 func.1(a=4,b=4) plot(....,..., title("a=4, b=4")) If I'm calling func.1 with different arguments, I want the plot title to reflect that. A small detail is that func.1 might have an argument with a default like c=a+b. I tried using expression but couldn't get it to work. Is there a way to do this using expression() ? -- Sancar Adali [[alternative HTML version deleted]] ______________________________________________ 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.
My function is like this sim.res<-gaussian_simulation(p=3, r=4, q=3, c=0.1,d=2, Wchoice = "avg", pre.scaling = TRUE, oos = TRUE, alpha = NULL, n = 100, m = 100, nmc = 100) which is defined as gaussian_simulation <- function(p, r, q, c, d = p-1, pprime1 = p+q, # cca arguments pprime2 = p+q, # cca arguments Wchoice = "avg", pre.scaling = TRUE, oos = TRUE, alpha = NULL, n = 100, m = 100, nmc = 100) and I want to title the plot after I invoke the gaussian_simulation function sim.res<-gaussian_simulation(p=3, r=4, q=3, c=0.1,d=2, Wchoice = "avg", pre.scaling = TRUE, oos = TRUE, alpha = NULL, n = 100, m = 100, nmc = 100) plot(sim.res) title("p=3, r=4, q=3, c=0.1,d=2") On Sat, Aug 28, 2010 at 12:53 AM, Sancar Adali <sadali@gmail.com> wrote:> What I want to do is put the arguments I supply to a function into the > title of a plot > Say I'm calling func.1 > func.1(a=4,b=4) > plot(....,..., title("a=4, b=4")) > If I'm calling func.1 with different arguments, I want the plot title to > reflect that. > A small detail is that func.1 might have an argument with a default like > c=a+b. I tried using expression but couldn't get it to work. > > Is there a way to do this using expression() ? > > -- > Sancar Adali > >-- Sancar Adali Johns Hopkins University Graduate Student [[alternative HTML version deleted]]