Beginner's questions (figures, bibliography) with Sweave/R/LaTeX---my first document

后端 未结 2 1795
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 17:31

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

相关标签:
2条回答
  • 2021-01-25 18:02

    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}
    
    0 讨论(0)
  • 2021-01-25 18:19

    Sweave does not take care of your bibliography, so you have to compile it by yourself; I believe some people have automated this job in their R scripts, but I would recommend you to use LyX if you are an experienced LaTeX user. LyX has official support to Sweave, and it takes care of everything you want in LaTeX intelligently (including bibliography). See the manual: https://github.com/downloads/yihui/lyx/sweave.pdf

    0 讨论(0)
提交回复
热议问题