2015-02-06 3 views
0

Sweave (저는 LaTeX에 대해 잘 알고 있습니다. 특히 학생으로서의 나날을 형성합니다).R Sweave - 텍스트와 플롯이 서로 다른 두 개의 파일로 인쇄됩니다.

사용 방법에 대한 아이디어를 얻으려는 시도는 this intro입니다.

기본적으로 예제 파일 (아래 참조)을 Rstudio에 복사하고 "PDF 컴파일"을 클릭합니다.

하지만 테스트와 같은 R 출력의 텍스트가 내 .Rnw 파일과 동일한 이름의 PDF로 인쇄되도록하는 반면, 플롯은 Rplots.pdf라는 다른 파일로 인쇄물을 가져옵니다.

플롯과 텍스트를 같은 파일로 인쇄하려면 어떻게해야합니까? 제가 놓친 부분이 있다면 미리 사과 드리겠습니다, 오늘 Sweave를 처음으로 사용합니다.

testSweave.Rnw는 :

\documentclass{article} 

\usepackage{graphicx, verbatim} 
\setlength{\textwidth}{6.5in} 
\setlength{\textheight}{9in} 
\setlength{\oddsidemargin}{0in} 
\setlength{\evensidemargin}{0in} 
\setlength{\topmargin}{-1.5cm} 

\begin{document} 
\SweaveOpts{concordance=TRUE} 
\begin{center} 
{\bf \Large Stat 500 Assignment 1\\} 
\end{center} 

Using the rock data in the datasets package. First we do some plots:\\ 
\setkeys{Gin}{width=.3\linewidth} 
<<>>= 
data(rock) 
require(ggplot2) 
plot1 = qplot(x=area, y=log(perm), data=rock) + theme_bw() + geom_smooth(col="red") 
print(plot1) 
@ 
%% lattice and ggplots must be inside a print statement to show up 
<<>>= 
print(plot1 + aes(x = peri)) 
@ 
<<>>= 
print(plot1 + aes(x = shape)) 
@ 

Now go back and remove the \%\% comments on the line 15 above here 
to set each plot width to .3 
times linewidth, and the three plots should fit on one line. If you leave a  blank line between the three code chunks above, they will start on new lines. 

Summary of the linear model: 
<<>>= 
    rock.lmfit <- lm(log(perm) ~ ., rock) 
    summary(rock.lmfit) 
@ 

<<>>= 
xtable::xtable(summary(rock.lmfit)$coef, digits=5) 
@ 
<<>>= 
rock.rlmfit = MASS::rlm(log(perm) ~ ., rock) 
xtable::xtable(summary(rock.rlmfit)$coef, digits = 4) 
    ## assumes that you have the xtable package available. It creates latex  tables. 


#To print any R object use a \verb|\Sexpr{any_R_object}| statement like this: 
#AIC of the linear model is \Sexpr{AIC(rock.lmfit)}. 
@ 

\end{document} 

답변

0

나는 해결책을 발견! 왜 그들이 인트로에서 이것을 생략했는지는 모르겠지만 어쨌든 "fig = TRUE"문장을 추가하는 것이 트릭을 만들었습니다.

예. 첫 번째 청크 :

<<>>= 
data(rock) 
require(ggplot2) 
plot1 = qplot(x=area, y=log(perm), data=rock) + theme_bw() + geom_smooth(col="red") 
print(plot1) 
@ 

내가해야 할 일을했을 모두는 stament 추가했다 :

<<fig = TRUE>>= 
data(rock) 
require(ggplot2) 
plot1 = qplot(x=area, y=log(perm), data=rock) + theme_bw() + geom_smooth(col="red") 
print(plot1) 
@ 

를 그리고 이제 모두 하나 개의 파일로 인쇄됩니다.