[R] Loop for main title in a plot
David Winsemius
dwinsemius at comcast.net
Thu Apr 25 07:11:53 CEST 2013
On Apr 24, 2013, at 9:22 PM, Eva Günther wrote:
> 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")))
>
> }
>
I have not quite figured out what the exact goal is but this shows how to loop with expression that have evaluated component: .... bquote is your friend:
for (trial in 1:length(a)) {
plot(x=a,y=b, # you were at the very least missing an x and y argument
main=bquote( italic(i)-.(trial)^th~choice))
}
... and you had too many quoted elements. Plotmath `paste` is usually not needed. Learn to use * and ~.
David.
> 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.
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list