[R] ggplot, qplot in loop

Albin Blaschka albin.blaschka at gmail.com
Thu Sep 25 13:17:59 CEST 2008


Dear List,

yes, me again trying to work with qplot ;-)

I would like to make several single plots within a loop, like this 
(simplified and so on...):

trials <- c("A","B","C")
mycolours <- ("wheat","darkolivegreen","lightgreen",
	"khaki","darkseagreen","orange","chocolate4","gray75")


for (i in 1:length(trials)) {

     sql <- paste("select trial, cover_of, dateofsurvey, cover
		from mytable where trial = '",trials[i],"'
     mydata <- (sqlQuery(channel, sql))
     mytitle <- paste("Development of Cover, ", trials[i],",sep = "")
     myplot <- qplot(dateofsurvey, cover, data=mydata, geom="area",
  		fill=cover_of, main = mytitle,
		ylab="projective Cover[%]", xlab = "Year")
     myplot <- myplot + scale_fill_manual(values = mycolours)
}

If I have no loop, everything works, with the loop, no graphics device 
is openend, nothing happens, but the variables are filled with data 
(checked on the commandline), the SQL is executed, the result from the 
database is available, but nothing gets produced.

If I execute all variants by hand (all different sql-statements), the 
respective graphic is produced, but put together in the loop, it does not...

OS: WinXP, R version 2.7.0 (2008-04-22)

What do I have missed?

Thank you in advance,
Albin


-- 
| Albin Blaschka, Mag.rer.nat.
| Etrichstrasse 26, A-5020 Salzburg
| * www.albinblaschka.info * www.thinkanimal.info *
| - It's hard to live in the mountains, hard but not hopeless!



More information about the R-help mailing list