Hi all, I have been using ggplot for a few months and ran into this porblem, I am trying to use ggplot in a for loop and it is not working. if I do the following: data=as.data.frame(cbind(rnorm(10),rnorm(10),rnorm(10))) ############ pp=ggplot(data, aes(x=(1:10), y=data[,1])) pp=pp+geom_line(aes(x=(1:10),y = data[,1]),lty=2) pp=pp+geom_line(aes(x=(1:10),y = data[,2]),lty=2) pp=pp+geom_line(aes(x=(1:10),y = data[,3]),lty=2) print(pp) ############ I get what I want, all 3 lines on the plot,
but this does NOT work: ################### pp=ggplot(data, aes(x=(1:10), y=data[,1])) for(i in 1:3){ pp=pp+geom_line(aes(x=(1:10),y = data[,i]),lty=2) } print(pp) ################ this does not work... I know I can do it using the group varable, but I would like to use for loops sometimes and want to know if you can do it. thank, Tarek [[alternative HTML version deleted]] ______________________________________________ R-help@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.