R: tiff( ) won't compress or set resolution to 300 ppi

♀尐吖头ヾ 提交于 2019-12-06 09:12:46

问题


I am trying to save some graphs using R for publication. I want to have them compressed with lzw and have the resolution at 300. For some reason it won't allow me to do this. In fact, it seems like R is ignoring some of the variables I set.

For the code example,

tiff(file="file.tiff", 
            width=6.83, height=6.83, units="in", 
            pointsize="12", compression = "lzw", 
            bg="white", res=300, antialias = "none" )

outputs an uncompressed file of size 28 x 28 inches and a resolution of 72 ppi.

A reproducable example would be

hist(rnorm(1000))
dev.off()

Here is the output of ImageMagick for file.tiff

Image: file.tiff
  Format: TIFF (Tagged Image File Format)
  Class: DirectClass
  Geometry: 2049x2049+0+0
  Units: PixelsPerInch
  Type: PaletteAlpha
  Base type: TrueColor
  Endianess: MSB
  Colorspace: sRGB
  ...
  Compression: None
  ...
  Filesize: 16.8MB

I tested this on another Apple running 10.7 and get the same results. As can be seen, even when using the options to compress and set the resolution at 300 dpi, the output does not follow the options.


回答1:


I verified your example with R 2.15.1 on GNU/Linux by appending

hist(rnorm(1000))
dev.off()

to your tiff() call and checked the resulting file "file.tiff" with ImageMagick's command line tool identify (most output omitted):

Image: file.tiff
  Format: TIFF (Tagged Image File Format)
  Class: DirectClass
  Geometry: 2049x2049+0+0
  Resolution: 300x300
  Print size: 6.83x6.83
[...]
  Compression: LZW
[...]
  Filesize: 70KB
[...]

The R command seems to do exactly what you intend to do. I suspect that either you create the TIFF file not in the manner you describe or the tool you use to check the TIFF file's properties is faulty.



来源:https://stackoverflow.com/questions/12609816/r-tiff-wont-compress-or-set-resolution-to-300-ppi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!