通过选择后记输出提高绘图质量
我仍在学习 Sweave
和 R
。我下面有一个示例代码,它读取数据文件并绘制它。我选择 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}
我想了解更多有关改进的一些事情:
我在绘图周围有一个框框。如何控制其线宽?
我使用
cex.axis=1.5
作为轴注释大小。如果我将其更改为cex.axis=3
,那么 x 轴上的值就会变大,并且它们与刻度线重叠。有没有办法将 x 轴值放置得离绘图远一点?y 标签
Hello
在图中H
字母的顶部被截断。如何解决此问题?如何将 x 标签
Wonderful
或 y 标签Hello
移离绘图更远?如果我们查看绘制的曲线,尽管数据集的初始值为 (0,0),但轴并非从 (0,0) 开始。如何控制轴使其从 (0,0) 开始?
多谢...
I am still learning Sweave
and R
. I have below a sample code that reads in a data file and plots it. I am choosing the postscript
option as I like ending up with an EPS
file. There are a number of things that I would like to improve with the plot. Here is my code with my own comments for my own learning:
\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}
Some things that I would like to know more about an improve:
I have a boxed frame around the plot. How to control its line width?
I am using
cex.axis=1.5
for the axis annotation size. if I change it to saycex.axis=3
then the values on the x-axis get big and they overlap with the tickmarks. Is there a way to then place the x-axis values a bit lower further away from the plot?The y-label
Hello
is truncated at the top of theH
letter in the plot. How to fix this?How to move either the x-label
Wonderful
or y-labelHello
further away from the plot?If we look at the plotted curve, the axes do not start at (0,0) though the initial values are (0,0) for the data set. How to control the axes so that they start at (0,0)?
Thanks a lot...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“我在绘图周围有一个方框。如何控制它的线宽?”
“我使用 cex.axis=1.5 作为轴注释大小。如果我将其更改为 cex.axis=3 ,那么 x 轴上的值会变大并且它们与刻度线重叠。有没有办法将 x 轴值放置在离绘图更远的地方?”
“y 标签 Hello 在图中 H 字母的顶部被截断。如何修复此问题?”
“如何将 x 标签 Wonderful 或 y 标签 Hello 移离绘图更远?”
“如果我们查看绘制的曲线,尽管数据集的初始值为 (0,0),但轴并非从 (0,0) 开始。如何控制轴,使其从 (0,0) 开始?”
所以该图的R代码如下:
不太漂亮,但它确实说明了控制功能。基本上你需要花更多的时间在帮助(par)页面上。
"I have a boxed frame around the plot. How to control its line width?"
"I am using cex.axis=1.5 for the axis annotation size. If I change it to say cex.axis=3 , then the values on the x-axis get big and they overlap with the tickmarks. Is there a way to then place the x-axis values a bit lower further away from the plot?"
"The y-label Hello is truncated at the top of the H letter in the plot. How to fix this?"
"How to move either the x-label Wonderful or y-label Hello further away from the plot?"
"If we look at the plotted curve, the axes do not start at (0,0) though the initial values are (0,0) for the data set. How to control the axes so that they start at (0,0)?"
So the R code for the figure is below:
Not pretty, but it does illustrate the control functions. Basically you need to spend more time on the help(par) page.