简体   繁体   English

使用Sweave和Latex,情节是空的

[英]Plots are empty using Sweave and Latex

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. 我想用R获得的图形进行报告。在这里,我向您展示了我设计的site_rose(site_ref)site_time_series(site_ref)生成的图像。 在此输入图像描述

在此输入图像描述

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. 但是在运行sweave('Profile.Rnw')并获得Profile.tex之后,我获得了Profile-002.pdf和Profile-003.pdf,这些最后两个文档都有0KB。 And so I get a .pdf report without any figure at all. 所以我得到了一个没有任何数字的.pdf报告。 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(...) 这两个函数的代码太大而不能在这里显示,这些函数没有任何外推因为得到图我只调用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 . 但是,如果您使用latticeggplot2不在ggplot2lattice出来的对象上调用print 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而不是Sweave knitr does not have this problem. knitr没有这个问题。 In general I would recommend using knitr instead of Sweave. 一般来说,我建议使用knitr而不是Sweave。

Is that the whole Sweave file? 这是整个Sweave文件吗? You won't be able to re-use variables that are defined in your current environment variable when creating a Sweave document. 在创建Sweave文档时,您将无法重用当前环境变量中定义的变量。 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. Sweave的重点是从头到尾重现一些分析,所以这不是一个好的方法。

I'd recommend including whatever analysis is necessary to generate the site_ref variable, among others in this Sweave document. 我建议包括生成site_ref变量所需的任何分析,以及此Sweave文档中的其他变量。

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. 如果您坚持使用快捷方式,则可以保存当前的R环境并将其作为Sweave文档中的第一个命令加载,以提供对这些变量的访问。

Use Stangle to extract the R code from your Sweave document, then create a new R session and try running that code. 使用Stangle从Sweave文档中提取R代码,然后创建一个新的R会话并尝试运行该代码。 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. 您应该能够在空的环境中运行Sweave文档中包含的R代码并使其成功运行。 Then you're ready to render it as a PDF. 然后,您就可以将其渲染为PDF格式了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM