【问题标题】:Improving the quality of a plot with postscript output chosen选择 postscript 输出来提高绘图的质量
【发布时间】:2011-12-03 08:29:21
【问题描述】:

我还在学习SweaveR。我在下面有一个示例代码,它读取数据文件并绘制它。我选择postscript 选项,因为我喜欢以EPS 文件结尾。我想通过情节改进很多事情。这是我的代码和我自己的 cmets 供我自己学习:

\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) 开始?

非常感谢...

【问题讨论】:

  • 据我所知,您的任何问题都与 SWeave 无关。由于将示例代码加载到 SWeave 中比仅 R 更麻烦,因此请通过删除所有 SWeave 内容来编辑您的问题。那我去看看。
  • @Andrie 我将来会尝试将我的 R 和 Sweave 查询分开。现在我已经得到了这篇文章的答案。

标签: r plot par


【解决方案1】:

“我在地块周围有一个框框。如何控制它的线宽?”

 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 Wonderful 或 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代码如下:

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"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-24
  • 2017-04-26
  • 1970-01-01
  • 1970-01-01
  • 2011-10-02
  • 2016-05-31
  • 1970-01-01
相关资源
最近更新 更多