如何提高R中绘图的分辨率? [英] How can I increase the resolution of my plot in R?

查看:2614
本文介绍了如何提高R中绘图的分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中进行简单绘图,希望生成的图像具有很高的分辨率.我尝试仅在输出图像代码中指定较大的高度和宽度参数,但这只会使具有模糊数据点的大型图像成为可能.

I am making simple plots in R and want the resulting images to be very high resolution. I tried just specifying large height and width parameters in the output image code, but this just makes a large image with fuzzy data points.

我当前的代码如下:

png(filename="simple_graphic.png", width=5600, height=1000)
depth_plot <- c(a large list of data)
plot(depth_plot, type="o", col="blue", log="y",)
dev.off()

任何帮助优化此代码以提高每个数据点的分辨率的方法都将受到赞赏!

Any help optimizing this code to make the resolution of each data point higher is much appreciated!

推荐答案

此问题有几种可能的答案,请谨慎对待注释,以教您其中只是给你.我将通过提供他们所暗示的内容来破坏这一点,但还要提出另一个问题:

There are several possible answers to this question, and the comments are being careful to try to teach you where to find the answer vice just giving it to you. I'll spoil that by providing that to which they allude, but also present another question:

  1. 答案:在对png的调用中使用res=300(或更高版本).从help(png)中,它指出默认的ppi(每英寸像素数)为72,低于您想要的精细分辨率图. 300对于大多数打印机和屏幕来说都是不错的,YMMV.

  1. The answer: use res=300 (or higher) in your call to png. From help(png), it states that the default ppi (pixels per inch) is 72, below what you want for fine-resolution graphs. 300 is decent for most printers and screens, YMMV.

png(filename="simple_graphic.png", res=300) # perhaps width/height as well
# ...
dev.off()

  • 另一个问题:我最能显示我的图形的格式是什么?许多使用R制作图形的人常常忽略了这一点,这很不幸但很容易解决:使用基于矢量的图像格式.如果您使用的是Powerpoint或Word,那么最好制作一个增强的图元文件格式(EMF)文件.

  • Another question: in what format can I best show my graph? This is often overlooked by many people making graphs with R, and is unfortunate but easy to remedy: use a vector-based image format. If you are using Powerpoint or Word, then you may be better off making an enhanced metafile format (EMF) file.

    install.packages('devEMF') # just once
    library(devEMF)
    emf(filename="simple_graphic.emf", width=1024, height=800)
    # ...
    dev.off()
    

    如果您可以使用可缩放矢量图形(SVG)格式的图像(例如Inkscape,Scribus等),则只需使用svg(...)代替emf(...).相同的选项/规则适用.

    If you are able to use the image in a scalable vector graphic (SVG) format (e.g., Inkscape, Scribus, ...), then merely use svg(...) in place of emf(...). Same options/rules apply.

    类似地,如果您是LaTeX,则可以使用pdf(...)(相同的语法)直接进入pdf.

    Similarly, if you're LaTeX, you can go straight to pdf using pdf(...) (same syntax).

    NB:使用这些基于矢量(基于PNG等基于栅格)的图像格式的一种好处是,如果您希望/需要以一种您不知道R中的方式精巧绘制图形,您可以使用Inkscape之类的文件来打开EMF/SVG/PDF,以便轻松地修改线条(颜色,粗细),文本(字体,大小,位置),框,箭头等.然后Inkscape将允许您导出到EMF中, SVG,PDF,PNG等...

    NB: one benefit of going to one of these vector-based (vice raster-based such as PNG) image formats is that if you want/need to finesse the graph in ways that you don't know how in R, you can open the EMF/SVG/PDF in something like Inkscape in order to easily modify lines (color, thickness), text (font, size, location), boxes, arrows, etc. And Inkscape will allow you to export into EMF, SVG, PDF, PNG, ...

    这篇关于如何提高R中绘图的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆