2011-12-03 27 views
0

我仍在學習SweaveR。我在下面有一個示例代碼,它讀入一個數據文件並繪製它。我選擇postscript選項,因爲我喜歡以EPS文件結束。有很多事情我想要改善情節。這裏是我的代碼跟我自己對我自己的學習評論:提高所選附記輸出的繪圖質量

\documentclass[a4paper,12pt]{article} 
\usepackage{Sweave} %%%%%% 
\SweaveOpts{eps=TRUE} 

\begin{document} 

<<echo=FALSE, results=hide>>= 
test.frame<-data.frame(ratio= c(0.0, 144.321, 159.407, 178.413, 202.557), value= c(0, 0.84, 0.8925, 0.945, 0.9975)) 
@ 


<<echo=FALSE,results=hide,eval=TRUE>>= 
postscript('doudou.eps', 
       width=7, height=6, 
       colormodel="cmyk", 
       family = "ComputerModern", 
       horizontal = FALSE, 
       onefile=FALSE, 
       paper = "special", 
       encoding = "TeXtext.enc", 
       pagecentre=FALSE) 

with(test.frame,plot(ratio, value, ylab= "Hello", 
            xlab="Wonderful", 
            type="o",  # line and markers 
            bty="o",   # box around graph 
            lty="solid",  # solid line or put 1 
            lwd=3,   # line width 
            pch=1,   # or enclose symbol in quotes 
            cex=3,    # size of markers 
            cex.lab=2,  # label size 
            cex.axis=1.5, # axis annot size problem if big 
            cex.main=2,   # main title size 
            xaxp=c(0, 200, 4), #c(x1, x2, n) 
            col=2,    # plotting color 
            xlim=c(0,200), 
            yaxt = "n",   #suppresses axis 
            main=" My curve")) 

axis(2,seq(0,1, by=0.5), las=2,cex=3,cex.lab=2,cex.axis=1.5,cex.main=2) 

dev.off() 
@ 

\begin{figure}[htbp] 
\begin{center} 
\includegraphics[width=0.8\textwidth]{doudou.eps} 
\end{center} 
\end{figure} 


\end{document} 

一些事情,我想知道更多關於改進:

  1. 我周圍有情節封閉式車架。如何控制其線寬?

  2. 我正在使用cex.axis=1.5作爲軸註釋尺寸。如果我將其更改爲cex.axis=3,則x軸上的值變大並且與tickmarks重疊。有沒有辦法將x軸值稍微偏離曲線圖?

  3. y標籤Hello被截斷在圖中H字母的頂部。如何解決這個問題?

  4. 如何將x標籤Wonderful或y標籤Hello遠離圖表?

  5. 如果我們看繪製的曲線,儘管數據集的初始值爲(0,0),但軸不從(0,0)開始。如何控制軸以使它們從(0,0)開始?

非常感謝......

+0

據我所知,你的問題都沒有涉及SWeave。由於將示例代碼加載到SWeave比R更麻煩,請刪除所有SWeave內容來編輯您的問題。然後我會看看。 – Andrie

+0

@ Andrie我將嘗試在未來分離我的R和Sweave查詢。現在我已經獲得了這篇文章的答案。 – yCalleecharan

回答

4

「我身邊有情節,如何控制其線寬的盒裝框架?」

box(lwd=3) 

「我使用cex.axis = 1.5軸標註尺寸。如果我改變它說cex.axis = 3,那麼在x軸上的值變大,他們與刻度線重合。有沒有辦法讓x軸的值稍微偏離劇情?「

par(mgp=c(3,1.5,0)) # second element is number of lines below the box for the labels 

「的y標籤你好在情節爲H字母的頂部被截斷。如何解決這一問題?」

# use par() to increase left margins 

「如何從情節或者移動的X標籤精彩或y標籤你好漸行漸遠?」

par(mgp=c(4,1.5,0)) # First element in mgp vector 

「如果我們看一下繪製的曲線,軸不(0,0)開始,雖然初始值(0,0)的數據集。如何控制軸,使他們從(0,0)開始?「

..., xaxs="i", yaxs="i", ... # can be done in `par` or in the plot call 

所以對於數字將R代碼如下: So the R code for the figure is below:

postscript('doudou.eps', 
       width=7, height=6, 
       colormodel="cmyk", 
       family = "ComputerModern", 
       horizontal = FALSE, 
       onefile=FALSE, 
       paper = "special", 
       encoding = "TeXtext.enc", 
       pagecentre=FALSE) 
par(mgp=c(4,1.5,0), mai=c(1.5, 1.5, 1.5, .75)) # using inches as the spacing unit 
with(test.frame, plot(ratio, value, ylab= "Hello", 
          xaxs="i", yaxs="i", 
            xlab="Wonderful", 
            type="o",  # line and markers 
            bty="o",   # box around graph 
            lty="solid",  # solid line or put 1 
            lwd=3,   # line width 
            pch=1,   # or enclose symbol in quotes 
            cex=3,    # size of markers 
            cex.lab=2,  # label size 
            cex.axis=3, # axis annot size problem if big 
            cex.main=2,   # main title size 
            xaxp=c(0, 200, 4), #c(x1, x2, n) 
            col=2,    # plotting color 
            xlim=c(0,200), 
            yaxt = "n",   #suppresses axis 
            main=" My curve")) 

axis(2,seq(0,1, by=0.5), las=2,cex=3,cex.lab=2,cex.axis=1.4, cex.main=2) 
box(lwd=3) 
dev.off() 

不漂亮,但它確實說明了控制功能。基本上你需要花更多的時間在幫助(par)頁面上。

+1

爲徹底!在圖上面的代碼行中,你有'axs =「i」'這應該是'xaxs =「i」'。 – Gregor

+1

@shujaa:對,你是。 –

+0

@非常感謝。 1票贊成這兩個意見。 – yCalleecharan