Hi all, I'm a newbie R developer, am trying to dotplot a few graphs using a for loop. The following code works fine but once I wanna plot inside a loop, nothing happens.> for(i in 1:1){dotplot(y~x)} > y <- c(1,2,3) > x <- c('a','b','c') > dotplot(y~x)> for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case)Nothing happens. I appreciate your advice on what is going wrong? Thanks. Best, Tony
When plotting in loops, you need to wrap your plot call in print(). On Sat, Apr 18, 2009 at 2:14 PM, Qifei Zhu <zhu_qifei at yahoo.com.sg> wrote:> Hi all, > > I'm a newbie R developer, am trying to dotplot a few graphs using a for > loop. > > The following code works fine but once I wanna plot inside a loop, nothing > happens. >> for(i in 1:1){dotplot(y~x)} >> y <- c(1,2,3) >> x <- c('a','b','c') >> dotplot(y~x) > >> for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case) > Nothing happens. > > I appreciate your advice on what is going wrong? Thanks. > > Best, > Tony > > ______________________________________________ > 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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~
Qifei Zhu wrote:> Hi all, > > I'm a newbie R developer, am trying to dotplot a few graphs using a for > loop. > > The following code works fine but once I wanna plot inside a loop, nothing > happens. >> for(i in 1:1){dotplot(y~x)} >> y <- c(1,2,3) >> x <- c('a','b','c') >> dotplot(y~x) > >> for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case) > Nothing happens.dotplot is a lattice function that need to be print()-ed which happened before automatically (as you'd type x in it is printed). Uwe Ligges> I appreciate your advice on what is going wrong? Thanks. > > Best, > Tony > > ______________________________________________ > 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.