28

A journal we are sending an article to is asking for the following:

To ensure the best reproduction quality of your figures we would appreciate high resolution files. All figures should preferably be in TIFF or EPS format... and should have the following resolution:
Graph: 800 - 1200 DPI
Photo: 400 - 800 DPI
Color (only CMYK): 300 - 400 DPI (DPI = dots per inch)

Since I am sending a graph, I am trying to save it using tiff.

Here is the code I am using:

tiff(filename = "c:\\aaa.tiff", 
     res = 800, pointsize = 2)
plot(1:100)
dev.off()    

But sadly, it produces a very "bulky" image - and if I where to not use pointsize = 2, I would get the error message:

Error in plot.new() : figure margins too large

Any suggestions?

Falko
  • 17,076
  • 13
  • 60
  • 105
Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • 1
    How about exporting to pdf/ps and then using ImageMagick or some other tool to convert to tiff? – Roman Luštrik Aug 29 '10 at 16:44
  • I could - but I might lose data in the meantime. Also, there is something basic here that I am missing - and I would like to learn it (wouldn't you? :) ) – Tal Galili Aug 29 '10 at 16:45
  • 1
    Export it to SVG, by doing such, you'll get no quality loss, cause it's vectorised. You can export SVG with `RSvgDevice` and `Cairo`. – aL3xa Aug 29 '10 at 17:18
  • @aL3xa pdf and ps are vector formats too. – mbq Aug 29 '10 at 17:26
  • Of course, but can you play with PDF/PS in Inkscape and/or Corel like you can with SVG files? – aL3xa Aug 29 '10 at 17:52
  • 1
    You haven't explained why you cannot use eps -- also a vector format that works well. What's wrong with that? – Dirk Eddelbuettel Aug 29 '10 at 18:22
  • @aL3xa Of course. @Dirk Very complex plots for instance -- they can halt pdf reader or break printing (not mentioning file sizes). Also I think eps has some problems with transparency. – mbq Aug 29 '10 at 20:35
  • @aL3xa: Yes, Inkscape deals pretty well with PDF – nico Aug 29 '10 at 21:51
  • 1
    Hello everyone - just to update you that I ended up using the eps format for the plots I sent. Thanks everyone for helping in this (especially for not answering my question - but what I needed) – Tal Galili Sep 01 '10 at 17:06

4 Answers4

31

One thing you should do is use the compression parameter.

For instance:

tiff("outfile.tif", compression = "lzw")

LZW is a lossless compression format, so you will not lose any data, but you will definitely reduce filesize.

nico
  • 50,859
  • 17
  • 87
  • 112
  • How can you rasterise in `pdf(filename)`? - - I tried `pdf(filename, compression = "lzw")` but it is not supported. I just need the figure in LaTeX presenation. Should I use tiff instead? – Léo Léopold Hertz 준영 Nov 15 '16 at 20:46
18

short answer:

It's a bulky file because the higher the resolution raster file (TIFF) then the larger the file.

The other option, EPS, is like PDF or PS. Just save in any of those. That's a vector image format and one they said was acceptable. It will be more compact and of higher quality (unless your figure contains an enormous number of points or lines.)

long answer:

One format they asked for is TIFF, a raster format. It saves the information as a value representing each pixel in the image. If the image is 100 DPI and 5" square then that's 500x500 and it saves 250000 pixels of information. As the resolution of the image gets higher and the image size stays constant then the points of information needed goes up. At 200 DPI it's 1000x1000 and 1e6 pixels of information. This explains why your file is so bulky.

In order to have a quality printed image at 5" square you would need about 300-400 DPI (dots per inch). That way you won't see each of those individual little pixels that make up the image. If it's at a lower resolution then the image is still 5" x 5" but each individual square block (pixel) that makes up the image is so large you can see them. That's why they asked for that resolution. Otherwise, text and lines in your graphs would appear blocky, jaggy, or blurry. It's why text on your computer screen (only around 100 DPI these days) isn't nearly as high quality as printed on a piece of paper (usually at least 300 dpi).

The other format they asked for was EPS. This is encapsulated postscript. Since it's a single page file PS, or postscript, would be equivalent. And, PDF is also similar. These are all vector formats, essentially the same vector format (they can contain raster format images too but let's ignore that).

A vector format file saves the information about how the image was drawn but not about each pixel. If you have an x-axis 3" long placed 0.5" from the bottom of the image then the vector file knows this description. Each feature of the graph is described in the file. Because of this, for simple drawings it is vastly more compact than any raster representation at a given image quality. Furthermore, it scales in size without losing quality. You simply ask it to draw the image at 6" x 6" instead of 5" x 5" and it scales each of the instructions for drawing the components of the image up as well. Therefore, even though the PDF or EPS file will be more compact, it will print at the highest quality.

Send a PDF or PS file and don't worry about the resolution.

John
  • 23,360
  • 7
  • 57
  • 83
  • It is not true that publishers that want EPS will also accept PDFs; conversion may be sometimes tricky. – mbq Aug 29 '10 at 20:42
  • i've seen this exact same request a dozen times or more and never had it fail. Nevertheless, eps() will work just fine. – John Aug 30 '10 at 01:34
  • For me it once failed; so it depends on technical editor preference I guess. – mbq Aug 30 '10 at 09:30
  • 2
    A note to future readers: changing the resolution does not actually increase the pixels, as in the first paragraph of the answer; by default the width and height are set at 480 pixels per inch. The OP's problem is that the resolution was changed without changing the size; at 800dpi, the size is 1.67 inches square. The OP changed the font to fit, but not the other elements of the plot (such as the points and lines) so they seemed much bigger than the should. To make this work with tiff format, the width and height need to be changed; see mbq's answer for details. – Aaron left Stack Overflow Oct 23 '11 at 18:30
  • I picked a fixed size of the image in the explanation that is about how raster images work in general, not about the command per se. So, if the image size stays the same size and you increase resolution then the file size, and number of pixels, goes up. The OP's initial problem of having a large file is about a lot of pixels and is going to get worse when they increase the image size. – John Aug 08 '12 at 12:39
11

When you increase resolution (res), the effective size of a plot decreases, and so the margin error jumps out. Try to make bigger picture with greater width and height (in theory, to make a plot of a same virtual size, it should be new_(width|height)=res/72*old_(width|height).
Still, as romunov suggested, it is a better idea to use ImageMagick; you won't loose quality.

mbq
  • 18,510
  • 6
  • 49
  • 72
2

I would suggest you to use devEval from the R.devices library.

I had this issue myself and solved it thanks to this :

  options("devEval/args/path"=file.path(Folder_of_Output))
  devEval("tiff", name="Name_output", width=120, height=800, {
  barplot(data, main="imagetitle");
  legend("top", legend =c("text of legend"))
  })

For me it worked like a charm and the file was saved directly without issue.

user2100721
  • 3,557
  • 2
  • 20
  • 29