I want to use tikz() function in tikzDevice package so that it generates a pdf file to be included in the bigger tex file. Below code works, but directly inserts tikz commands in the output tex file. This works: <<name = tikzFig, echo = FALSE, results = tex>>= This does not work: <<name = tikzFig, echo = FALSE, fig = TRUE>>Full code is given below: \documentclass{article}\usepackage{tikz} Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice} package. \begin{figure}\begin{center} <<name = tikzFig, echo = FALSE, results = tex>>library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@ \caption{Example of tikz graph}\label{tikzExampleFig}\end{center}\end{figure} \end{document} [[alternative HTML version deleted]]
On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote:> I want to use tikz() function in tikzDevice package so that it generates a pdf file to be included in the bigger tex file. Below code works, but directly inserts tikz commands in the output tex file. > This works: > <<name = tikzFig, echo = FALSE, results = tex>>> This does not work: > <<name = tikzFig, echo = FALSE, fig = TRUE>>> Full code is given below: > \documentclass{article}\usepackage{tikz} > Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice} package. > \begin{figure}\begin{center} > <<name = tikzFig, echo = FALSE, results = tex>>> library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@ > \caption{Example of tikz graph}\label{tikzExampleFig}\end{center}\end{figure} > \end{document}Your example isn't usable -- please post in plain text, not HTML. I can't tell whether you are trying to use Sweave or knitr. If you're using knitr, see the discussion of dev = "tikz" in <yihui.name/knitr>. If you're using Sweave, you probably need pgfSweave. Duncan Murdoch
On 17/01/2016 3:40 PM, Duncan Murdoch wrote:> On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote: >> I want to use tikz() function in tikzDevice package so that it generates a pdf file to be included in the bigger tex file. Below code works, but directly inserts tikz commands in the output tex file. >> This works: >> <<name = tikzFig, echo = FALSE, results = tex>>>> This does not work: >> <<name = tikzFig, echo = FALSE, fig = TRUE>>>> Full code is given below: >> \documentclass{article}\usepackage{tikz} >> Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice} package. >> \begin{figure}\begin{center} >> <<name = tikzFig, echo = FALSE, results = tex>>>> library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@ >> \caption{Example of tikz graph}\label{tikzExampleFig}\end{center}\end{figure} >> \end{document} > > Your example isn't usable -- please post in plain text, not HTML. > > I can't tell whether you are trying to use Sweave or knitr. If you're > using knitr, see the discussion of dev = "tikz" in > <yihui.name/knitr>. If you're using Sweave, you probably need > pgfSweave. >Okay, I see from your subject line that you're using Sweave. I don't think you can do better than your "This works" example without switching to knitr. Duncan Murdoch
Resending as a useable example \documentclass{article} \usepackage{tikz} \begin{document} Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package.? \begin{figure} \begin{center} <<name = tikzFig, echo = FALSE, results = tex>># % <<name = tikzFig, echo = FALSE, fig = TRUE>> # %<<tikzFig, echo = FALSE, fig = TRUE>># setwd("/Users/nareshgurbuxani/Documents/tex/tikz") library(tikzDevice) tikz(console = TRUE) plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab = "sin(x)") dummy <- dev.off() @ \caption{Example of tikz graph} \label{tikzExampleFig} \end{center} \end{figure} \end{document} ----------------------------------------> Subject: Re: [R] tikzDevice and Sweave > To: naresh_gurbuxani at hotmail.com; r-help at r-project.org > From: murdoch.duncan at gmail.com > Date: Sun, 17 Jan 2016 15:40:24 -0500 > > On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote: >> I want to use tikz() function in tikzDevice package so that it generates a pdf file to be included in the bigger tex file. Below code works, but directly inserts tikz commands in the output tex file. >> This works: >> <<name = tikzFig, echo = FALSE, results = tex>>>> This does not work: >> <<name = tikzFig, echo = FALSE, fig = TRUE>>>> Full code is given below: >> \documentclass{article}\usepackage{tikz} >> Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice} package. >> \begin{figure}\begin{center} >> <<name = tikzFig, echo = FALSE, results = tex>>>> library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@ >> \caption{Example of tikz graph}\label{tikzExampleFig}\end{center}\end{figure} >> \end{document} > > Your example isn't usable -- please post in plain text, not HTML. > > I can't tell whether you are trying to use Sweave or knitr. If you're > using knitr, see the discussion of dev = "tikz" in > <yihui.name/knitr>. If you're using Sweave, you probably need > pgfSweave. > > Duncan Murdoch >