2011-12-03 5 views
0

まだSweaveRを学習しています。データファイルを読み込んでプロットするサンプルコードを以下に示します。私はEPSファイルで終わるのが好きなのでpostscriptオプションを選択しています。プロットで改善したい点がいくつかあります。選択したポストスクリプト出力を使用してプロットの品質を改善

\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軸の値が大きくなり、目盛りと重なってしまいます。プロットから少し離れた位置にx軸の値を配置する方法はありますか?

  3. yラベルHelloは、プロットのH文字の上部で切り捨てられています。これを修正するには?

  4. xラベルWonderfulまたはyラベルHelloをプロットから遠ざけるにはどうすればよいですか?

  5. プロットされた曲線を見ると、データセットの初期値は(0,0)ですが、軸は(0,0)で始まらないことに注意してください。彼らは(0,0)で始まるように軸を制御する方法?

おかげでたくさん...

+0

私の知る限り、あなたの質問はSWeaveに関連していません。 SWeaveへのサンプルコードの読み込みはもっと面倒ですので、すべての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ラベルhelloはプロットの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)で始まる? " 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() 

きれいではありませんが、それは制御機能を説明します:

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

だからフィギュアのためのRコードは以下の通りです。基本的には、ヘルプ(パー)ページでもっと時間を費やす必要があります。

+1

徹底的に+1!プロットの上のコード行では、 'axs =" i "'は 'xaxs =" i "'でなければなりません。 – Gregor

+1

@shujaa:そうです。 –

+0

@ありがとうございます。両方のコメントに対して1票アップ。 – yCalleecharan

関連する問題