[R] Sweave Dynamic Graph Question

Ista Zahn izahn at psych.rochester.edu
Sat Nov 20 01:05:27 CET 2010


Hi Cameron,
This is a Sweave FAQ:
http://www.stat.uni-muenchen.de/~leisch/Sweave/FAQ.html#x1-11000A.9

-Ista

On Fri, Nov 19, 2010 at 4:13 PM, cameron <raymond.fu at invesco.com> wrote:
>
> 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.
>
> ______________________________________________
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list