关于Sweave/R/LaTeX的初学者问题(图形,书目)-我的第一个文档 [英] Beginner's questions (figures, bibliography) with Sweave/R/LaTeX---my first document

查看:75
本文介绍了关于Sweave/R/LaTeX的初学者问题(图形,书目)-我的第一个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是从SweaveR开始.在这里,我正在使用R来输出一些数据,并且还试图包含一个绘图.该代码不编织.我有一个来自Web的Sweave示例,可以很好地在RStudioLaTeX中进行编译.

I am just starting with Sweave and with R. Here I am using R to output some data and I am also trying to include a plot. The code does not sweave. I have one Sweave example from the web that compiles well in RStudio with LaTeX.

\documentclass[a4paper]{article}
\begin{document}
<<echo=TRUE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=FALSE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=TRUE>>= 
test.frame<-read.table(file="apples.d",header=T,sep= "")
names(test.frame)
head(test.frame)
class(test.frame)
@
\begin{figure}[htbp]
\begin{center}
\setkeys{Gin}{width=0.5\textwidth}
<<echo=FALSE,fig=TRUE,width=4,height=4>>=
plot(year,value)
@
\end{center}
\end{document}

并且文件apples.d包含:

and the file apples.d contains:

#Number of apples I ate
year value
8   12050  #year 2008  
9   15292  #year 2009 
10  23907  #year 2010 
11  33997  #year 2011

我在做什么错了?

其他相关问题:

Sweave文档是否支持普通的LaTeX bibliography文件.如何进行编译?

Does a Sweave document support normal LaTeX bibliography file. How to do the compilation?

非常感谢...

推荐答案

已纠正多个问题,并以%%%%或####

Several problems corrected, marked by %%%% or ####

\documentclass[a4paper]{article}
\begin{document}
<<echo=TRUE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=FALSE>>=
x <- rnorm(100)
xm <- mean(x)
xm
@

<<echo=TRUE>>= 
##### Remove all comments from your data file 
test.frame<-read.table(file="apples.d",header=T,sep= "")
names(test.frame)
head(test.frame)
class(test.frame)
@

\begin{figure}[htbp]
\begin{center}
\setkeys{Gin}{width=0.5\textwidth}
<<echo=FALSE,fig=TRUE,width=4,height=4>>=
#### Must tell plot where to get the data from. Could also use test.frame$year
with(test.frame,plot(year,value))
@
\end{center}
\end{figure}
\end{document}

这篇关于关于Sweave/R/LaTeX的初学者问题(图形,书目)-我的第一个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆