Sweave: side by side dynamic graphs

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Sweave: side by side dynamic graphs

Felipe Carrillo
Hi all:
I'm trying to create some side by side dynamic graphics on the same page but I am running into some problems. I am able to create side by side figures only if I import them into my PDF. see the example bellow:

\documentclass[12pt]{article}
\usepackage{color,cite,graphicx}% to put in axodraw
\usepackage{latexsym,amssymb,epsf}
\begin{document}
%Import two figures side by side. Please Replace the 'bar' picture with any
% jpeg picture to make this example reproducible.
\begin{figure}[h]
\centerline{\mbox{\includegraphics[width=3.00in]{bar}}
\mbox{\includegraphics[width=3.00in]{bar}}}
\end{figure}

% I would like to create two dynamic graphics here side by side
%but isn't working.
\begin{figure}[h]
\centering
<<fig.R,echo=F,fig=T,width=2.5,height=2.5>>=
plot(1:10}
@
\caption{This is the first graph}
\end{figure}
\begin{figure}
\centering
<<fig.R,echo=F,fig=T,width=3,height=3>>=
plot(1:15)
@
\caption{This is the second graph}
\end{figure}
\end{document}

Thanks for your help

Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Sweave: side by side dynamic graphs

Dieter Menne
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:

> I'm trying to create some side by side dynamic graphics on the same page but

Thanks for the example; there was a minor typo so that it did not run "plot(}",
and a major problem that could have caused serious problem (happens to me quite
often due to copy and paste)

<<fig.R,echo=F,fig=T,width=2.5,height=2.5>>=

You must give the << sections with graphics different names, otherwise the wrong
picture will be used.

For side-by-side, you simply plot side by side, or use minipages when captions
are needed for both figures. In the first case, trellis graphs are much more
space-conservative.

Dieter



\documentclass[12pt]{article}
% For a minimal example, please remove all special packages
\begin{document}
\begin{figure}[h]
\centerline{\mbox{\includegraphics[width=3.00in]{bar}}
\mbox{\includegraphics[width=3.00in]{bar}}}
\end{figure}

\begin{figure}[ht]
\centering
<<Rdouble,echo=F,fig=T,width=5,height=2.5>>=
par(mfrow=c(1,2))
plot(1:10)
plot(1:10)
@
\caption{When you do not need separate captions, this is the easiest way.}
\end{figure}

\begin{figure}[ht]
\begin{minipage}[b]{0.5\linewidth}
\centering
<<RsingleA,echo=F,fig=T,width=2.5,height=2.5>>=
plot(1:10)
@
\caption{First figure}
\label{fig:figure1}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\centering
<<RsingleB,echo=F,fig=T,width=3,height=3>>=
plot(1:15)
@
\caption{Second figure}
\label{fig:figure2}
\end{minipage}
\end{figure}
\end{document}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Sweave: side by side dynamic graphs

Felipe Carrillo
Thanks Dieter, I didn't know about 'minipage' but I was actually going to try par'(mfrow=c(1,2))' this morning. Thanks for your help again.



--- On Sun, 11/2/08, Dieter Menne <[hidden email]> wrote:

> > I'm trying to create some side by side dynamic
> graphics on the same page but
>
> Thanks for the example; there was a minor typo so that it
> did not run "plot(}",
> and a major problem that could have caused serious problem
> (happens to me quite
> often due to copy and paste)
>
> <<fig.R,echo=F,fig=T,width=2.5,height=2.5>>=
>
> You must give the << sections with graphics different
> names, otherwise the wrong
> picture will be used.
>
> For side-by-side, you simply plot side by side, or use
> minipages when captions
> are needed for both figures. In the first case, trellis
> graphs are much more
> space-conservative.
>
> Dieter
>
>
>
> \documentclass[12pt]{article}
> % For a minimal example, please remove all special packages
> \begin{document}
> \begin{figure}[h]
> \centerline{\mbox{\includegraphics[width=3.00in]{bar}}
> \mbox{\includegraphics[width=3.00in]{bar}}}
> \end{figure}
>
> \begin{figure}[ht]
> \centering
> <<Rdouble,echo=F,fig=T,width=5,height=2.5>>=
> par(mfrow=c(1,2))
> plot(1:10)
> plot(1:10)
> @
> \caption{When you do not need separate captions, this
> is the easiest way.}
> \end{figure}
>
> \begin{figure}[ht]
> \begin{minipage}[b]{0.5\linewidth}
> \centering
> <<RsingleA,echo=F,fig=T,width=2.5,height=2.5>>=
> plot(1:10)
> @
> \caption{First figure}
> \label{fig:figure1}
> \end{minipage}
> \hspace{0.5cm}
> \begin{minipage}[b]{0.5\linewidth}
> \centering
> <<RsingleB,echo=F,fig=T,width=3,height=3>>=
> plot(1:15)
> @
> \caption{Second figure}
> \label{fig:figure2}
> \end{minipage}
> \end{figure}
> \end{document}
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.