[R] Sweave Dynamic Graph Question

cameron raymond.fu at invesco.com
Fri Nov 19 22:13:53 CET 2010


i have a time Series of IBM closing px from 1/1/2000 to today
I want to graph the time serie by dividing the graph by year and month
all the monthly graphs with the same year will go to one page.  so from
1/1/2000 to 11/19/2010.  i will have
11 pages, and each page will have 12 graphs (jan to dec) except for 2010.  

I am able to do it in R, but when i use sweave, I can only print the last
page.
any help would be greatly appreciated

Thanks
Cameron

#R code

library(fImport) 

IBM <- yahooSeries("IBM", from="2000-01-01") 

IBM.Close <- IBM[,"IBM.Close"]

rng=range(time(IBM.Close))

Syr  <- as.numeric(format(rng[1],"%Y"))
Eyr  <- as.numeric(format(rng[2],"%Y"))
Smth <- as.numeric(format(rng[1],"%m"))

for( yr in Syr:Eyr){
	par(mfrow=c(4,3))
	
	Temp1 <- IBM.Close[which(format(time(IBM.Close),"%Y")==yr),]
	Temp3 <- tapply(Temp1[,1],as.yearmon(time(Temp1)),FUN=mean)

	for(i in Smth:length(Temp3)){
			
		i <- ifelse(i < 10, paste(0,i,sep=""),i)
		Date <- paste(i,yr,sep="-")
		
		Temp2 <- IBM.Close[which(format(time(IBM.Close),"%m-%Y")==Date),]
		plot(time(Temp2),Temp2,type="l",main=paste(factor(as.numeric(i), labels =
month.name[as.numeric(i)]),yr,sep="-")) 
		
	}
	
}

# my sweave code (pass in IBM.Close)

\pagebreak
\subsection{Graph}
\begin{figure}[!htbp]
\begin{center}


<<plot1, echo = FALSE, results = hide, fig = TRUE, height = 8>>=


rng=range(time(IBM.Close))

Syr  <- as.numeric(format(rng[1],"%Y"))
Eyr  <- as.numeric(format(rng[2],"%Y"))
Smth <- as.numeric(format(rng[1],"%m"))

for( yr in Syr:Eyr){
	par(mfrow=c(4,3))
	
	Temp1 <- IBM.Close[which(format(time(IBM.Close),"%Y")==yr),]
	Temp3 <- tapply(Temp1[,1],as.yearmon(time(Temp1)),FUN=mean)

	for(i in Smth:length(Temp3)){
			
		i <- ifelse(i < 10, paste(0,i,sep=""),i)
		Date <- paste(i,yr,sep="-")
		
		Temp2 <- IBM.Close[which(format(time(IBM.Close),"%m-%Y")==Date),]
		plot(time(Temp2),Temp2,type="l",main=paste(factor(as.numeric(i), labels =
month.name[as.numeric(i)]),yr,sep="-")) 
		
	}
	
}


@

-- 
View this message in context: http://r.789695.n4.nabble.com/Sweave-Dynamic-Graph-Question-tp3051003p3051003.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list