2011-12-02 26 views
0

我是R的新手,Sweave的新手,我正在試驗圖形。下面是一個示例代碼:R/Sweave:前綴和圖形文件命名

\documentclass[a4paper]{article} 
\usepackage{Sweave} %%%%%% 
\SweaveOpts{eps=true} 
\begin{document} 

<<echo=FALSE>>= 
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991)) 
@ 

\SweaveOpts{prefix.string=Evolution} 
<<label=amount,echo=FALSE,results=hide>>= 
postscript('doudou.eps', 
      width=6, height=7, 
      colormodel="cmyk", 
      family = "ComputerModern") 
with(test.frame,plot(year, value)) 
dev.off() 
@ 

\begin{figure}[htbp] 
\begin{center} 
\includegraphics[width=1\textwidth,angle=90]{doudou.eps} 
\end{center} 
\end{figure} 

\end{document} 

What I want to do above?

若要在EPS文件,我將讓我可以在Sweave文件本身\includegraphics命令手動控制。

,我試圖給一個適當的文件名圖:前綴Evolution和標籤amount,使得產生的EPS數字將被命名爲Evolution-amount.eps

What is going wrong?

正如你所看到的,我在Rpostscript選項即doudou.eps插入一個文件名。如果我不這樣做,一個名爲Rplots.ps的文件由R創建。

所以我的代碼很好地忽略了我想給我的圖形文件的前綴和標籤。

而且我明確地問以後由\includegraphicsdoudou.eps

How I want it to be?

爲了能夠有前綴和標籤,因爲我在圖中的文件名如上所述,雖然我還有過在Sweave文件\includegraphics命令手動控制。這可能嗎?

What is the use of this?

說我寫文章,我有不同的部分數字。因此,這將是不錯的東西,如:

\SweaveOpts{prefix.string=Paper2} 

<<label=section2,echo=FALSE,results=hide>>= 

和例如我在postscript選項指定:model.eps

那麼這個數字將被命名Paper2-section2.model.eps例如。這是可行的嗎?

而且我需要以某種方式手動把這個名字?在下面的\includegraphics命令中。

非常感謝......


更新:09年12月2011年

與cbeleites的幫助下,緊密的解決方案是:

\documentclass[fleqn, a4paper,12pt]{article} 
\usepackage[latin1]{inputenx} 
\usepackage[T1]{fontenc} 
\usepackage{Sweave} %%%%%% 
\SweaveOpts{eps=TRUE} 



\begin{document} 

<<echo=FALSE>>= 
test.frame<-data.frame(year=8:11, value= c(12050,15292,23907,33991)) 
@ 

\SweaveOpts{prefix.string=Paper2} 

<<label=section2, echo=FALSE,results=hide>>= 
ps.options (width=6, height=7, colormodel="cmyk", family = "ComputerModern") 
@ 


<<label=section2, fig=TRUE, include = TRUE, echo=FALSE>>= 
with(test.frame,plot(year, value)) 
@ 

\end{document} 

在編譯時我得到的EPS和名爲Paper2-section2的PDF文件。這和我想的一樣接近。

+0

請不要在問題主體中添加對問題的答案。這變得非常混亂。 SO上的每個問題都應該成爲一個問題。 – Andrie

回答

3

您需要使用一個圖形塊。

<<fig=TRUE, include = FALSE>>= 
    with(test.frame,plot(year, value)) 
    @ 
  • 可以傳遞更多的選擇圖中的塊,如寬度和高度。

  • 對於更高級的選項,使用r後記選項:

    <<>>= 
    ps.options (colormodel="cmyk", family = "ComputerModern") 
    @ 
    
  • 如果選擇僅適用於一個數字,你可能更容易關閉不圖塊並設有手動\includegraphics。不過,您可以將文件名賦予ps文件,就好像它是由Sweave圖塊生成的一樣。

  • 如果\includegraphics的唯一原因是,你要控制它的選項,看看graphicx宏」 Gin

    \begin{figure}[htbp] 
    \begin{center} 
    \setkeys{Gin}{width=\linewidth} 
    <<fig=TRUE>>= 
    with(test.frame,plot(year, value)) 
    @ 
    \end{center} 
    \end{figure} 
    

我想杜松子酒將與輪流工作爲好,但它沒有。請參閱https://tex.stackexchange.com/a/31013以獲得解釋和可能的解決方案。但是,如果旋轉僅僅是因爲數字出現橫向偏移(而不是你希望它們橫向偏移),則可以用R中正確的ps設置來解決這個問題(RSiteSearch()? postscript應該有所幫助)。

+0

@ cbeleites謝謝。當你這樣做的時候,我們完全忽略了Postscript的選項,比如Computer Modern的字體系列等等。 – yCalleecharan

+0

@ yCalleecgaran:(沒有時間去實際嘗試,但)看看手冊。有可能使用鉤子,這可能會幫助你結合'ps.options'。或者,根據手冊,您可以設置自己的圖形設備定義。 – cbeleites

+0

@ cbeleites感謝您向我介紹手冊。也就是說,這個帖子並不是一個大問題。我總是可以手動寫入文件名。 – yCalleecharan

相關問題