2

Click here to load reader

Latex Sweave tikZ Sample Output

Embed Size (px)

DESCRIPTION

Example output for a Website post. A sample LaTeX document produced after integrating LaTeX with R code using the tikZ package.

Citation preview

Page 1: Latex Sweave tikZ Sample Output

How to Embedding R Code in LATEX

Lighton Phiri

September 13, 2012

Sweave is a function built right within R to facilitate dynamic reporting. Figure1 is an example of an R plot dynamically created with Sweave and the tikzDevicepackage.

Search and Browse Navigability Similarity General

Average UX Ratings

Su

bje

cts

0

1

2

3

4

5IntuitiveSimpleSatisfiedExpectedResponseEffectiveBeneficial

Figure 1: An R Barplot Integrated with LATEX

Listing 1 is the R command used to produce the ux-evaluation.tex TEXfile thatis used within the main LATEXdocument; Listing 2 shows the Sweave code thatwas used to generated the barplot in Figure 1; and Listing 3 shows the portionof the LaTeX document that uses the Sweave output file as input.

1

Page 2: Latex Sweave tikZ Sample Output

Listing 1: R Command for Processing Sweave File

R CMD Sweave ux−e v a l u l a t i o n .Rnw

Listing 2: R Sweave Code - ux-evaluation.Rnw

<< f i g=FALSE, echo=FALSE>>=

# load requ i r ed l i b r a r i e s and de f i n e environmentrequire ( ’ t i k zDev i c e ’ )t i k z ( ’ ux−eva lua t i on . tex ’ , standAlone=FALSE, bareBones=FALSE,

width =4.5 , he ight =2.5)

# de f i n e data sourcebono lou i <− read . table ( ” bono lou i . dat ” , header=T, sep=”\ t ” )

# de f i n e p l o t areapar ( xpd=T, mar=par ( ) $mar+c ( 0 , 0 , 0 , 3 ) , cex =0.6 , f ont =2)barplot ( as . matrix ( bono lou i ) , be s ide=TRUE, xlab=”Average UX Ratings ” ,

ylab=” Subjec t s ” ,yl im=c ( 0 , 6 ) , col=rainbow ( 7 ) , l a s =1,space=c (0 , 3 ) , names . arg=

c ( ” Search and Browse” , ” N a v i g a b i l i t y ” ,” S i m i l a r i t y ” , ” General ” ) , axes=FALSE, ann=FALSE, font . lab =2)

axis (2 , l a s =1, at=(seq (0 , 5 , by=1)))legend (38 ,5 , c ( ” I n t u i t i v e ” , ” Simple ” ,

” S a t i s f i e d ” , ”Expected” ,”Response” , ” E f f e c t i v e ” , ” B e n e f i c i a l ” ) ,

f i l l =rainbow ( 7 ) , bty=”o” , text . width =5);abline (h=(seq ( 0 , 5 , 0 . 5 ) ) , col=” l i g h t g r a y ” , l t y=” dotted ” )#box (” inner ” , ” do t t ed ”)@

Listing 3: Portion of LaTeX Document

\documentclass [ a4paper , 10 pt ]{ a r t i c l e }\usepackage { t i k z }:\begin {document}:\begin { f i g u r e } [ ht ]\ c e n t e r i n g\ framebox [\ textwidth ] {\ input {ux−eva lua t i on . tex }

}\ capt ion {An R Barplot In t eg ra t ed with \LaTeX}\ l a b e l { r−barp lo t }

\end{ f i g u r e }:\end{document}

2