选择后记输出提高绘图质量

时间:2011-12-03 08:29:22

标签: r plot par

我还在学习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轴上的值会变大,并且它们会与刻度线重叠。有没有办法将x轴值放置在距离图更远的位置?

  3. y标签Hello在图中H字母的顶部被截断。如何解决这个问题?

  4. 如何将x-label Wonderful或y-label Hello更远离情节?

  5. 如果我们查看绘制的曲线,虽然数据集的初始值为(0,0),但轴不会从(0,0)开始。如何控制轴使它们从(0,0)开始?

  6. 非常感谢...

1 个答案:

答案 0 :(得分: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-label精彩或y-label Hello远离情节?”

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()

不漂亮,但确实说明了控制功能。基本上你需要花更多的时间在帮助(标准杆)页面上。