I want to make a report with the graphics I obtain with R. Here I show you both images produced with site_rose(site_ref)
and site_time_series(site_ref)
I designed.
But after running sweave('Profile.Rnw') and getting Profile.tex I obtain Profile-002.pdf and Profile-003.pdf that these last two documents have 0KB. And so I get a .pdf report without any figure at all. Here I show you the code:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\title{Anàlisi in situ emplaçament}
\author{Jonel Palou Visa}
\begin{document}
\maketitle
\begin{center}
<<fig=TRUE,echo=TRUE>>=
site_ref <- site_time_series(site_ref,peaks=T,stationary=T)
@
\end{center}
\begin{center}
<<fig=TRUE,echo=TRUE>>=
site_rose(site_ref)
@
\end{center}
\end{document}
I would like to know if there is a problem with the new device I call in order to plot the figures or what is my real problem. The code for both functions is too large to show here, there isn't any extrange in these functions because to get the figure I only call plot(...)
Without the code of the two functions you created it remains unclear what is going wrong. However, if you use either lattice
or ggplot2
not calling print
on the object that that came out of ggplot2
or lattice
. On the command line these kinds of plots work because print is then called implicitely. So:
print(site_rose(site_ref))
Should produce the correct result. Alternatively, you could start using knitr
instead of Sweave
. knitr
does not have this problem. In general I would recommend using knitr
instead of Sweave.
Is that the whole Sweave file? You won't be able to re-use variables that are defined in your current environment variable when creating a Sweave document. The whole point of Sweave is to reproduce some analysis from end-to-end, so that wouldn't be a good approach to take anyways.
I'd recommend including whatever analysis is necessary to generate the site_ref
variable, among others in this Sweave document.
If you insist on taking a shortcut, you could save your current R environment and load it in as the first command in the Sweave document to provide access to those variables.
Use Stangle
to extract the R code from your Sweave document, then create a new R session and try running that code. You'll probably get errors about undefined variables, or messages about functions not being defined. You should be able to run the R code contained in your Sweave document in an empty environment and have it work successfully. Then you're ready to render it as a PDF.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With