[R] Loop for main title in a plot

Blaser Nello nblaser at ispm.unibe.ch
Thu Apr 25 11:03:08 CEST 2013


You could use bquote. Something like this:

a<-c(1,2,3,4)
b<-c(1,2,3,4)
nTrials <- length(a)

for (trial in 1:nTrials) { 
  plot(x=a[1:trial], y=b[1:trial],
       ylab=expression(paste("Apple"["P"])),
       xlab=expression(paste("Banana"^"th")),
       main=bquote(italic("i-")~.(trial)^"th"~"choice"))                                                                                             
}

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Eva Günther
Sent: Donnerstag, 25. April 2013 06:22
To: r-help at r-project.org
Subject: [R] Loop for main title in a plot

Hi all,

I have a problem in including my plot in a loop. Here is a simple example for one plot:

# Plot simple graph with super- and subscript
a<-c(1,2,3,4)
b<-c(1,2,3,4)

plot(x=a,y=b,
    ylab=expression(paste("Apple"["P"])),
    xlab=expression(paste("Banana"^"th")),
    main=expression(paste(italic("i-")~"4"^"th"~"choice")))

Now I would like to include the titel (main) as a function of the number of trails for (trial in 1:nTrials) { plot(

main=expression(paste(italic("i-")~"trial"^"th"~"choice")))

}

e.g. nTrials = 5
The title should look like this:

5th plot: i ^th choice
4th plot: i-1 ^th choice
3th plot: i-2 ^th choice and so on

I have problems to create that, could you please help me?

Thank you!!

	[[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.



More information about the R-help mailing list