[R] : create a PDF file (text (print list) and grafics)

Stephen Tucker brown_emu at yahoo.com
Wed Jun 20 06:50:00 CEST 2007


Hi Ana,

There are two ways in which I imagine this can be done:
(1) create a layout [using layout()] and printing the text on a blank plot;
(2) using Sweave.

## === Method 1 example... ===

pdf()
layout(matrix(c(1,1,2,3),ncol=2,byrow=TRUE),widths=c(1,1),heights=c(3,2))
par(mar=c(0,0,5,0))
plot.new(); plot.window(xlim=c(0,1),ylim=c(0,1))
title("Title",cex.main=1.5)
text(0.4,0.5,adj=c(0,0),lab=
"> print(myList)
$a
[1] 1

$b
[1] 2")
par(mar=c(5,4,1,1))
boxplot(1:10)
hist(1:10)
dev.off()

## (there must be a more elegant way than pasting the output
## of print(myList) as a character string in text() but I can't
## think of it at the moment...

## === Method 2 (warning: I am not too familiar with Sweave
## but I understand that this is how it *should* work; this
## Sweave document will create a '.tex' file which you can then
## compile with latex - this site was helpful:
## http://www.stat.umn.edu/~charlie/Sweave/)  ===

\documentclass[a4paper]{article}
\title{Sweave Document}
\author{}
\date{}
\begin{document}
\maketitle

Text field here

<<echo=FALSE>>=
## computations to build 'myList' here (but not for printing)
## such as
myList <- list(a=1,b=2)
@
<<reg>>=
## this is for output
print(myList)
@ 

\begin{center}
<<fig =TRUE , echo =FALSE >>=
par(mfrow=c(1,2), oma=c(0,0,3,0),cex=0.5)
#Image
hist(controlo$quope,axes=T,plot=T,col="gray",xlab=
"Quope",main="Histograma",lwd=2)
boxplot(controlo$quope,col="bisque",lty=3,medlty=1,medlwd=2.5,main=
"Boxplot")     
mtext(regiao,cex=1.5,col="blue",adj=0.5,side=3,outer=TRUE) 
@
\end{center}
\end{document}

##



--- Ana Patricia Martins <ana.pmartins at ine.pt> wrote:

> Dear helpers,
> 
> I need help to create a PDF file like the example
> 
>  -----------------------------------
>  |	      Title				|
>  -----------------------------------
>  |						|
>  |		Text (print a list)	|		   
>  |						|
>  -----------------------------------
>  |			|		      |
>  |			|		      |
>  |    image		|     image	      |
>  |			|		      |
>  |			|		      |
>  -----------------------------------
> 
> 
>
pdf(paste(getwd(),"/Output/Controlo_Pesos",regiao,trimestre,substr(ano,3,4),
> 
> 		".pdf",sep="),height=13.7, paper="special")
> par(mfrow=c(1,2), oma=c(0,0,3,0),cex=0.5)
> 
> #Text field (????????????)
> #print(qual_pesos)# is a list
> 
> #Image
> hist(controlo$quope,axes=T,plot=T,col="gray",xlab=
> "Quope",main="Histograma",lwd=2)
> boxplot(controlo$quope,col="bisque",lty=3,medlty=1,medlwd=2.5,main=
> "Boxplot")     
> mtext(regiao,cex=1.5,col="blue",adj=0.5,side=3,outer=TRUE) 
> dev.off()
> 
> 
> 
> There is other way to do the same more easily
> Thanks in advance for helping me.
> Best regards.
> 
> Atenciosamente,
> Ana Patricia Martins
> -------------------------------------------
> Serviço Métodos Estatísticos
> Departamento de Metodologia Estatística
> INE - Portugal
> Telef:  218 426 100 - Ext: 3210
> E-mail: ana.pmartins at ine.pt <mailto:ana.pmartins at ine.pt> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> > ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list