Hi all, I want to do plot() in a loop to make 10 graphs, so I have some code like for (i in 1:10) { plot(... ... , xlab = expression(g[i]) ) } I expect g_1, g_2, and so on appear on x labels, but it simply prints g_i for each graph. Does anybody know how to get around this problem? Thanks. NL
Nanye Long said the following on 8/18/2008 3:00 PM:> Hi all, > > I want to do plot() in a loop to make 10 graphs, so I have some code like > > for (i in 1:10) { > plot(... ... , xlab = expression(g[i]) ) > } > > I expect g_1, g_2, and so on appear on x labels, but it simply prints > g_i for each graph. Does anybody know how to get around this problem? > Thanks. > > NL > > ______________________________________________ > 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.Try: par(mfrow = c(2, 5)) for (i in 1:10) { plot(1, 1, xlab = bquote(g[.(i)])) } HTH, --sundar
on 08/18/2008 05:00 PM Nanye Long wrote:> Hi all, > > I want to do plot() in a loop to make 10 graphs, so I have some code like > > for (i in 1:10) { > plot(... ... , xlab = expression(g[i]) ) > } > > I expect g_1, g_2, and so on appear on x labels, but it simply prints > g_i for each graph. Does anybody know how to get around this problem? > Thanks. > > NLTry this: par(mfrow = c(5, 2)) for (i in 1:10) plot(1, xlab = bquote(g[.(i)])) Note the use of bquote() and the use of .(i), which replaces 'i' with the value of i in each iteration. See ?plotmath for some examples and ?bquote HTH, Marc Schwartz