On Ben Bolker's advice I started using pgfSweave and tikzDevice. I'm struggling with getting R graphs into LaTeX.

This is my code for pgfSweave Rnw file:


\title{Minimal pgfSweave Example}
\author{Cameron Bracken}



This example is identical to that in the Sweave manual and is intended to
introduce pgfSweave and highlight the basic differences. Please refer to
the pgfSweave vignette for more usage instructions.
We embed parts of the examples from the \texttt{kruskal.test} help page
into a \LaTeX{} document:

# hey, a comment
print(kruskal.test(Ozone ~ Month, data = airquality )) # and another

\noindent which shows that the location parameter of the Ozone distribution varies
significantly from month to month. Finally we include a boxplot of the data:

  %notice the new options
  {\pgfkeys{/pgf/images/include external/.code=

    <<boxplot, echo=T, fig=T, width=3, height=3, tikz=T, external=T, highlight=T>>=
      boxplot(Ozone ~ Month, data = airquality,
        main='Ozone distribution',xlab='Month',ylab='Concentration')
   }% this brace ends the effect of `include external'
  \caption{This is from pgfSweave. Text is typset by \LaTeX\ and so matches the
           font of the document.}


which produces

pgfSweave output

and the tikzDevice Rnw code is





  <<inline, echo=FALSE, results=tex>>=
  tikz(console=TRUE, width=5, height=5)
  x <- rnorm (100)
  dummy <- dev.off()



which produces

tikzDevice output

My question is: What am I missing? Both Rnw codes do not produce R graphs in pdf to include in a LaTeX document. Any help will be highly appreciated.

  • I removed the thanks. This is just the style here. Any thanks is best expressed as voting for answers that help you.
    – qubyte
    Commented Nov 27, 2011 at 4:51
  • 1
    I don't think you can indent the <<...>> and @ lines. Does it work if you remove the indentation from those lines?
    – Aaron
    Commented Nov 27, 2011 at 4:56
  • @Aaron: You are absolutely right. Both codes are working after removing the indentation. Would you mind to include your comment as answer?
    – MYaseen208
    Commented Nov 27, 2011 at 5:03

1 Answer 1


In both cases, the Sweave chunks should not be indented.

When the Sweave driver (a part of R) parses the input file, it recognizes as chunks of R code blocks that begin with a << at the start of a line, and end with a @. Because your << is not at the start of a line, those blocks are never run as R code, and no plots are produced.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .