使用 R 绘图 - 倾斜的 eps 图像和分辨率问题
我想在 R 中创建函数的图形。代码是:
x <- seq(from=0, to=1, by=0.00001)
f <- function(x) ....
y <- f(x)
plot(x, y, xlab="x", ylab="f(x)", pch=16, cex=0.5)
min(y)
[1] 0.2291203
max(y)
[1] 0.7708797
当我从 RGui 将图形保存为 bmp 时,它看起来像 这里 这很好。当我将其保存为 eps 并包含在 LaTeX 中时:
<前><代码>\begin{图}[htbp] \定心 \includegraphics[scale=0.4]{./images/f-probart.eps} \结束{图}它是倾斜的,如此处的屏幕截图所示 怎么了?我猜想从 RGui 导出 eps 时存在问题,因为生成的 eps 在 IrfanView 中也显示为倾斜的。因此我怀疑这不是 LaTeX 包含代码错误...
我如何创建具有所请求分辨率(例如 244 dpi)的图形?是否有另一个包/函数允许我导出具有特定分辨率的 eps?
谢谢
I want to create a graphics of a function in R. The code is:
x <- seq(from=0, to=1, by=0.00001)
f <- function(x) ....
y <- f(x)
plot(x, y, xlab="x", ylab="f(x)", pch=16, cex=0.5)
min(y)
[1] 0.2291203
max(y)
[1] 0.7708797
When I save the graphics as bmp from RGui, it looks like here and this is fine. When I save it as eps and include in LaTeX with:
\begin{figure}[htbp] \centering \includegraphics[scale=0.4]{./images/f-probart.eps} \end{figure}
it is skewed, as shown in the screen capture from here
What is wrong? I guess there is a problem with exporting from RGui in eps, as the resulted eps is also shown skewed in IrfanView. Hence I suspect that is not the LaTeX inclusion code that is wrong...How could I create this graphics with a requested resolution, say 244 dpi? Is there another package/function that allows me to export eps with a specific resolution?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现您的错误,所以我猜这是您的系统特有的问题。如果我保存为 eps 并将其包含在 Latex 中(使用 Graphicx 包),则一切正常。请记住,如果您在 R 中使用 postscript() 函数,则还必须指定图片的宽度和高度。我可能是错的,但我认为它默认为 R 中图形窗口的默认值(这可以解释 eps 图片的尺寸)。
如果从图形窗口保存,通常应采用图形窗口的当前宽度和高度。在我的 R 版本上也是如此,但也许您的选项设置不同?检查 ps.options() 并查看宽度和高度是否为 0。如果不是这样,则可能是问题所在。
旁注:您可以使用 pdf 代替。请参阅 R 中的 ?pdf。它允许您指定图片的宽度和高度,并在 Latex 中正确再现。那么您应该使用 pdftex 来构建文件。
我的经验是,使用pdf图形和pdftex比通过PS更麻烦。事实上,在 Latex 中,不再需要通过 eps 来获得像样的 pdf。使用 pdftex 的另一个优点是您可以轻松地将所有图形格式组合在同一文档中。 (对于 EPS,您需要 epstopdf 软件包)
2) dpi 要求仅对网格图像有用,因此不适用于矢量化的 eps 和 pdf。我会使用 png,这是图表的最佳格式。请参阅函数 png() 中的选项 res。
或者,您可以以完全相同的方式将函数 bmp() 用于位图图形。不要忘记最后的 dev.off() 。
I cannot reproduce your error, so I guess it's something specific to your system. If I save as eps and include it in latex (using the graphicx package), everything works completely fine. Keep in mind that if you used the postscript() function in R, you have to specify the width and height of your picture as well. I could be wrong, but I think it defaults to the default values of the graphics window in R (which could explain the dimensions of your eps pictures).
If you saved from the graphics window, it normally should take the current width and height of the graphics window. It does so on my R version, but maybe your options are set differently? check ps.options() and see if width and height have value 0. If that's not the case, that could be the problem.
On a side-note : You could use pdf instead. See ?pdf in R. It allows you to specify the width and height of the picture, and reproduces correctly in Latex. You should use pdftex for building the file then.
My experience is that using pdf graphics and pdftex is less trouble than passing through PS. In fact, in latex there is no need to pass through eps any more to come to a decent pdf. Another advantage of using pdftex is that you can easily combine all graphics formats in the same document. (For EPS you need the epstopdf package)
2) the dpi requirement is only useful for grid images, so not for eps and pdf which are vectorized. I'd use png, that's the best format for graphs. See the option res in the function png().
Alternatively, you could use the function bmp() for bitmap graphics in exactly the same way. Don't forget the dev.off() at the end.
我用的是开罗套餐;代码是:
结果图看起来不错。然而,有一个问题:根据 @Joris Meys 的说法,dpi 对于矢量图形来说毫无用处;在这种情况下,为什么必须为 Cairo 功能指定 dpi?
I used the Cairo package; the code was:
The resulted graph looked fine. One question, however: according to @Joris Meys, the dpi is useless for vector graphics; in this case, why specifying dpi for the Cairo function is mandatory?