[R] Plotting graphs using FOR loop

ychu066 ychu066 at aucklanduni.ac.nz
Tue Nov 17 04:38:29 CET 2009


I have the following codes but can anyone make it shorter i.e making these
FOR loop into one loop ...
thanks...

par(mfrow=c(2,4))                 
for(i in 16:23){
hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100)) 
}   
png("histogram.png")
dev.off() 

par(mfrow=c(2,4))                 
for(i in 24:31){
hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100)) 
} 
png("histogram.png")
dev.off() 

par(mfrow=c(2,4))                 
for(i in 32:39){
hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100)) 
} 
png("histogram.png")
dev.off() 

par(mfrow=c(2,4))                 
for(i in 40:47){
hist(data[,i],main=paste(colnames(data)[i],sep=""),ylab="Frequency",xlim=c(1,5),xlab="Score",ylim=c(0,100)) 
} 
png("histogram.png")
dev.off() 


-- 
View this message in context: http://old.nabble.com/Plotting-graphs-using-FOR-loop-tp26383926p26383926.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list