[R] 300 dpi and eps:

Joshua Wiley jwiley.psych at gmail.com
Wed Dec 15 20:06:28 CET 2010


Hi Aldi,

Perhaps this will help slightly:

Dots per inch (DPI) or points (pixels) per inch (PPI) = number of
pixels/number of inches.

there are several ways of specifying the size of a graphic in R.  You
use the "width" and "height" argument regardless, but you can set a
third argument the "units" (for example see ?tiff) that you gave width
and height in (pixels, inches, centimeters, milimeters).  Which one
you will use really depends on your goals.  For example, if I am
making a graphic to be used on the web (i.e., it will be displayed on
a monitor which works in terms of pixels, not inches), the I might
use: width = 500, height = 350, units = "px".  But, if I wanted to
print something out on paper, and wanted the final product to be a 4"
x 6", and I wanted a resolution (i.e., x number of pixels per inch) of
300 DPI, I could use: width = 4, height = 6, units = "in", res = 300
(resolution is always in pixels per inch).  If I were to then look at
the resulting size of the graphic, it would be 4 * 300 x 6 * 300 =
1200 x 1800 pixels, which makes sense because we wanted 300 pixels per
each inch.  It is possible to manipulate the above formula
algebraically to get:

inches = number of pixels/DPI or resoultion

so I could get to the same 4" x 6" graph using:  width = 1200, height
= 1800, units = "px", res = 300

because, 1200/300 x 1800/300 = 4 x 6.  If you wanted the graph to fill
an entire page, with a certain number of dots per inch, the easiest
approach would be: width = page_width_in_inches, height =
page_height_in_inches, units = "in", res = your_desired_dots_per_inch

If you're still uncertain/confused, there is actually a lot of
literature available on this topic that is probably more erudite than
my simple explanation.  You could start with Wikipedia:
http://en.wikipedia.org/wiki/Dots_per_inch    and then just Google
terms like "dots per inch", "pixels per inch", until you're sick and
tired, tired and sick, and maybe a little drunk (depending, I suppose,
on how relatively fascinating/boring you find the topic).

Hope that helps,

Josh


On Wed, Dec 15, 2010 at 10:28 AM, Aldi Kraja <aldi at wustl.edu> wrote:
> Thank you Jeff for your advice,
> Maybe it was better my email subject to had been "high quality R graphs for
> publication" instead of "300 dpi and eps".
>
> a. In my latest response I was asking for any published paper/book (written
> by anybody in the R list) that describes how R handles vector graphs and
> raster graphs. Must be technical that Jeff did not like it. See the end of
> this email for a suggestion.
>
> But let's come to a more practical question:
>
> b. I was asking also how one handles in R the relation between page height,
> page width and pixels per unit.
>
> For example I find from the discussion list different responses:
>
> "EPS is perfectly acceptable in Word on a PC. The only proviso is that, as
> has been mentioned, Word will only display a low resolution bitmap "preview"
> of EPS image in the document on screen whilst editing. When printed to a
> postscript printer or converted to PDF via something like Distiller or via
> publishers' online submission tools, the figure will be in the best possible
> quality." (Simpson).
>
> "For publication, it would be rare to want to use a bitmapped format such as
> jpg/png, pdf and eps are vector based formats and would be generally
> preferred over the above." (Schwartz)
>
> The practical response I found for point b) is the following (by Wiley
> responding to someone else question):
> "You have set the resolution, but you have not set the width/height. The res
> argument generally controls how many pixels per inch (PPI which is often
> used similarly to DPI). So if you want 800 DPI and you want it to be a 4 x 4
> inch graph something like: tiff(file = "temp.tiff", width = 3200, height =
> 3200, units = "px", res = 800); plot(1:10, 1:10); dev.off(); This will make
> a file that is 3200 x 3200 pixels, with an 800 resolution gives you 3200/800
> = 4 inches. I would also recommend choosing some sort of compression or you
> will end up with a rather large file."
>
> So I come back to R tiff() function and see this example:
> tiff(filename = "Rplot%03d.tif", width = 480, height = 480, units = "px",
> pointsize = 12, compression = c("none", "rle", "lzw", "jpeg", "zip"),  that
> reminds also for the compression importance for large graphs produced.
>
> Following Wiley's example, if I use res=300 then I get 3200/300=10.66667
> inches for the size of the graph. So I wanted to see how Jeff or other
> listers handle these graph manipulations in R? Why width and height have to
> be the same size based on these examples? What happens if the paper is 8.5i.
> x 11i., what do you do? What is the best advice how to produce in R graphs
> that can be acceptable for publications?
>
> There are many good examples in R News for papers that explain best
> different aspects of plotting, but I would suggest someone competent in this
> area write a great paper to explain technicalities of "how to create a high
> quality R graph for publication" if this does not exist.
>
> TIA,
>
> Aldi
>
> On 12/15/2010 10:24 AM, Jeff Newmiller wrote:
>>
>> It is possible to embed a raster image inside eps, but AFAIK R does not do
>> this. Other than that, your questions do not apply to eps. Rendering
>> resolution only comes into play when you put it into a raster software (like
>> photoshop) or print it.
>>
>> Beyond that, we don't know what you are doing with the file after R
>> generates it, and this is not a digital publishing mailing list so this
>> isn't the right forum to continue this discussion.
>>
>> "Aldi Kraja"<aldi at wustl.edu>  wrote:
>>
>>> I have come around several times from R to A. Illustrator, or A.
>>> photoshop, and between them with PowerPoint. It is possible that the
>>> last one I reported was from PowerPoint.
>>> So from your postings it was made clear that postscript plot from R
>>> produces a vector graph.
>>>
>>> Can someone recommend some paper that makes clear the relation and
>>> distinctions between vector and raster graphics, but especially with
>>> some practical examples in regard to what is the relation between page
>>> (height and width) and dpi.
>>>
>>> For example if I plan to print high resolution graph in an image size
>>> of
>>> the A4 paper (8.5 inch x 11 inch) and from a journal it is required
>>> that
>>> the graph needs to have 300 dpi or more how one tells to the R
>>> graphical
>>> device to produce this setting?
>>>
>>> In A. photoshop for example I can define for a graph width in inches,
>>> height in inches and resolution in pixels/inch color model CMYK and 8
>>> bit. How one works in R?
>>>
>>> Or one saves the graph from postscript function as eps or tiff and you
>>> tell to the editor of the journal do whatever you want because I am
>>> done; I provided you already a vector graph that has infinite
>>> pixels?:-)
>>>
>>> Thank you in advance,
>>>
>>> Aldi
>>>
>>> On 12/15/2010 3:52 AM, Rainer M Krug wrote:
>>>>
>>>> -----BEGIN PGP SIGNED MESSAGE-----
>>>> Hash: SHA1
>>>>
>>>> On 12/15/2010 09:31 AM, Philipp Pagel wrote:
>>>>>>
>>>>>> Everything works fine to place them in a pdf file , or eps file,
>>>
>>> but
>>>>>>
>>>>>> when it comes to have a high quality of 300 dpi these graphs are
>>>
>>> not
>>>>>>
>>>>>> good. For example I open the eps file with Adobe Illustrator (AI)
>>>>>> and it shows that it is a 72dpi graph.
>>>>>
>>>>> This is simply not true: it's an eps and thus of essentually
>>>
>>> infinite
>>>>>
>>>>> resolution for all practial purposes.
>>>>
>>>> Just to clarify this: eps / ps are vector formats - i.e. it says in
>>>
>>> the
>>>>
>>>> file "draw a line from point x to point y". In contrast, bmp (and
>>>
>>> e.g.
>>>>
>>>> jpg, png, tiff) are raster formats: in these formats save the PICTURE
>>>
>>> of
>>>>
>>>> the line from point x to y.
>>>> Consequently, only raster formats have dpi ("dots" per inch).
>>>>
>>>>> So your problem is not with
>>>>> the R-generated eps but somewhere downstream from that. Any
>>>>> postprocessing, conversion or editing?
>>>>
>>>> Or in Adobe illustrator? It strikes me, that 72dpi is usually the
>>>
>>> screen
>>>>
>>>> resolution.
>>>>
>>>> Cheers,
>>>>
>>>> Rainer
>>>>
>>>>> cu
>>>>>        Philipp
>>>>>
>>>> - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>>>> Biology, UCT), Dipl. Phys. (Germany)
>>>>
>>>> Centre of Excellence for Invasion Biology
>>>> Natural Sciences Building
>>>> Office Suite 2039
>>>> Stellenbosch University
>>>> Main Campus, Merriman Avenue
>>>> Stellenbosch
>>>> South Africa
>>>>
>>>> Tel:        +33 - (0)9 53 10 27 44
>>>> Cell:       +27 - (0)8 39 47 90 42
>>>> Fax (SA):   +27 - (0)8 65 16 27 82
>>>> Fax (D) :   +49 - (0)3 21 21 25 22 44
>>>> Fax (FR):   +33 - (0)9 58 10 27 44
>>>> email:      Rainer at krugs.de
>>>>
>>>> Skype:      RMkrug
>>>> -----BEGIN PGP SIGNATURE-----
>>>> Version: GnuPG v1.4.10 (GNU/Linux)
>>>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>>>
>>>> iEYEARECAAYFAk0Ij8gACgkQoYgNqgF2egolFwCfbcSKiB4xyc7B/mOzdRRu2/dr
>>>> iOEAn1KoMR1C4RgYuRRIixUVtLbXN1zE
>>>> =W0bk
>>>> -----END PGP SIGNATURE-----
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>
>>> http://www.R-project.org/posting-guide.html
>>>>
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>> --
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>> ---------------------------------------------------------------------------
>> Jeff Newmiller                        The     .....       .....  Go
>> Live...
>> DCN:<jdnewmil at dcn.davis.ca.us>         Basics: ##.#.       ##.#.  Live
>> Go...
>>                                       Live:   OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#.
>>  rocks...1k
>>
>> ---------------------------------------------------------------------------
>> Sent from my phone. Please excuse my brevity.
>
> --
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list