The following code works mostly. It runs fine but... 1. Is there a way to increment the xlab for each graph? I would like to have Graph 1, Graph 2, etc. Right now it just gives me Graph i over and over again. 2. Is there a way to get the x-axis and y-axis to be bold or at least a darker color? Right now it is light gray. 3. Is there a way to modify this code to automatically save them? I assume the answer is do it manually. This is not the most important. for(i in 1:12){ hist(zNort1[,i], freq=FALSE, xlab="Graph i", col="blue", main="Standardized Residuals Histogram", ylim=c(0,1), xlim=c(-3.0,3.0)) zNortmin<-min(zNort1[,1]) zNortmax<-max(zNort1[,1]) zNortmean<-mean(zNort1[,1]) zNortsd<-sd(zNort1[,1]) X1<-seq(-3.0, 3.0, by=.01) lines(X1, dnorm(X1, zNortmean, zNortsd) , col="black") } -- View this message in context: http://r.789695.n4.nabble.com/histograms-and-for-loops-tp3503648p3503648.html Sent from the R help mailing list archive at Nabble.com.
This should work!! for(i in 1:12){ xLabel <- paste("Graph",i) plotTitle <- paste("Graph",i,".jpg") jpeg(plotTitle) print(hist(zNort1[,i], freq=FALSE, xlab=xLabel, col="blue", main="Standardized Residuals Histogram", ylim=c(0,1), xlim=c(-3.0,3.0)),axes = FALSE) axis(1, col = "blue",col.axis = "blue") axis(2, col= "red",col.axis = "red") zNortmin<-min(zNort1[,1]) zNortmax<-max(zNort1[,1]) zNortmean<-mean(zNort1[,1]) zNortsd<-sd(zNort1[,1]) X1<-seq(-3.0, 3.0, by=.01) lines(X1, dnorm(X1, zNortmean, zNortsd) , col="black") dev.off() } -- View this message in context: http://r.789695.n4.nabble.com/histograms-and-for-loops-tp3503648p3503758.html Sent from the R help mailing list archive at Nabble.com.
1. ?paste ?sprintf 2. ?par (look at col.axis) ?axis 3. ?pdf ?png ?dev.copy -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of wwreith > Sent: Friday, May 06, 2011 11:11 AM > To: r-help at r-project.org > Subject: [R] histograms and for loops > > The following code works mostly. It runs fine but... > > 1. Is there a way to increment the xlab for each graph? I would like to > have > Graph 1, Graph 2, etc. Right now it just gives me Graph i over and over > again. > > 2. Is there a way to get the x-axis and y-axis to be bold or at least a > darker color? Right now it is light gray. > > 3. Is there a way to modify this code to automatically save them? I > assume > the answer is do it manually. This is not the most important. > > for(i in 1:12){ > hist(zNort1[,i], freq=FALSE, xlab="Graph i", col="blue", > main="Standardized > Residuals Histogram", ylim=c(0,1), xlim=c(-3.0,3.0)) > zNortmin<-min(zNort1[,1]) > zNortmax<-max(zNort1[,1]) > zNortmean<-mean(zNort1[,1]) > zNortsd<-sd(zNort1[,1]) > X1<-seq(-3.0, 3.0, by=.01) > lines(X1, dnorm(X1, zNortmean, zNortsd) , col="black") > } > > > -- > View this message in context: http://r.789695.n4.nabble.com/histograms- > and-for-loops-tp3503648p3503648.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
On May 6, 2011, at 1:11 PM, wwreith wrote:> The following code works mostly. It runs fine but... > > 1. Is there a way to increment the xlab for each graph? I would like > to have > Graph 1, Graph 2, etc. Right now it just gives me Graph i over and > over > again. >Use the power of bquote. See modified code below.> 2. Is there a way to get the x-axis and y-axis to be bold or at > least a > darker color? Right now it is light gray.What do you mean by the "axis". The bounding box?, the ticks?, the labels?> > 3. Is there a way to modify this code to automatically save them? I > assume > the answer is do it manually. This is not the most important.?savePlot> > for(i in 1:12){ > hist(zNort1[,i], freq=FALSE, xlab=bquote("Graph "*.(i) ) , > col="blue", main="Standardized > Residuals Histogram", ylim=c(0,1), xlim=c(-3.0,3.0)) > zNortmin<-min(zNort1[,1]) > zNortmax<-max(zNort1[,1]) > zNortmean<-mean(zNort1[,1]) > zNortsd<-sd(zNort1[,1]) > X1<-seq(-3.0, 3.0, by=.01) > lines(X1, dnorm(X1, zNortmean, zNortsd) , col="black") > } > > > --David Winsemius, MD West Hartford, CT