Re: [R] Sweave Dynamic Graph Question

2010-11-23 Thread cameron


thx guys,  this is what i came up with.  it works fine, but too many lines
of code.

thanks again.
Cameron



\pagebreak
\section{General Value Graph Daily}
\setkeys{Gin}{width=1.1\textwidth}

results=tex,echo=FALSE=  

rng=range(time(pf4[[1]]))

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){

file1=paste(myfile, yr, sep=)  
Temp1 - pf4[[1]][which(format(time(pf4[[1]]),%Y)==yr),]
Temp3 - tapply(Temp1[,1],as.yearmon(time(Temp1)),FUN=mean)

cat(\\begin{figure}[!htbp]\n)
cat(\\begin{center}\n)

pdf(file=paste(file1,.pdf,sep=))

par(mfrow=c(4,3),mar=c(3,2,2,2))
for(i in Smth:length(Temp3)){

i - ifelse(i  10, paste(0,i,sep=),i)
Date - paste(i,yr,sep=-)

Temp2 - 
pf4[[1]][which(format(time(pf4[[1]]),%m-%Y)==Date),]
plot(Temp2[,Day],Temp2[,Daily
Value]/100,type=l,main=paste(factor(as.numeric(i), labels =
month.name[as.numeric(i)]),yr,sep=-)) 
}
  
dev.off() 
cat(\\includegraphics{, file1, }\n, sep=) 

cat(\\end{center}\n)
cat(\\caption{Volume Graph Analysis Daily ,yr,, x = business 
day, y =
in million}\n,sep=)
cat(\\label{fig3}\n)
cat(\\end{figure}\n\n)
} 
@
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Sweave-Dynamic-Graph-Question-tp3051003p3055407.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


[R] Sweave Dynamic Graph Question

2010-11-19 Thread cameron

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@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.


Re: [R] Sweave Dynamic Graph Question

2010-11-19 Thread Ista Zahn
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...@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@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

__
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.


Re: [R] Sweave Dynamic Graph Question

2010-11-19 Thread Dirk Eddelbuettel

On 19 November 2010 at 13:13, cameron 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

It's essentially an Sweave FAQ: you can only have one pdf (or ps) file per R
'snippet' so you have to rethink your code logic a little.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

__
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.


Re: [R] Sweave Dynamic Graph Question

2010-11-19 Thread Yihui Xie
This limitation actually comes from the LaTeX command
\includegraphics{}. It is not impossible to insert animations into
LaTeX, e.g. you can use the LaTeX package 'animate'.

The R package 'animation' has a wrapper saveLatex() which can help you
generate a PDF file containing animations, provided you have
appropriate tools installed (mainly pdflatex and Acrobat Reader). Here
is an example for your graphs:

library(animation)
saveLatex({
library(zoo)
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 = -))
}
}
}, interval = 1, latex.filename = IBM-2000-2010.tex)


I still need to modify this function a little bit to adapt to Sweave,
so that you can use the option 'results=tex' to insert animation
chunks in real-time in Sweave.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Fri, Nov 19, 2010 at 6:06 PM, Dirk Eddelbuettel e...@debian.org wrote:

 On 19 November 2010 at 13:13, cameron 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

 It's essentially an Sweave FAQ: you can only have one pdf (or ps) file per R
 'snippet' so you have to rethink your code logic a little.

 Dirk

 --
 Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

 __
 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.


__
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.