Best practice

106 views
Skip to first unread message

kw

unread,
Mar 21, 2012, 7:13:32 AM3/21/12
to ggp...@googlegroups.com
Folks,
   I have been putting together some graphics for a report.

I use Pages on the Mac and my colleagues use Word on PC's. This seems to work OK.

My question is what is the best way to create graphics to be inserted into the report? Do I create them full size and then shrink them after I import them into the document? Should I create them as PDF or jpg or png?

For example I tried to use pdf("file.name", width = 3, height = 3) with a graph I had already programmed. I'm sure you can guess what the result was: the graph was full size but squished in a tiny space.

I know these are general questions but I am sure some of you have come upon and solved these issues in your own work.

Thanks so much for your time,
KW

Ben Bond-Lamberty

unread,
Mar 21, 2012, 7:23:03 AM3/21/12
to ggp...@googlegroups.com
>what is the best way to create graphics to be inserted into the report?

I'd suggest:

-- create the graphics full-size, and then shrink as necessary in Pages
-- avoid JPG because it's lossy
-- don't use PDF for graphics with *lots* of points, as the resulting
file size may be very large

Ben

Roman Luštrik

unread,
Mar 21, 2012, 7:25:48 AM3/21/12
to kw, ggp...@googlegroups.com
ggsave is pretty smart about saving to files. Give it a whirl and see if it gets you where you want.





--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2



--
In God we trust, all others bring data.

ONKELINX, Thierry

unread,
Mar 21, 2012, 8:46:51 AM3/21/12
to kw, ggp...@googlegroups.com

I prefer to create the graphics directly at the dimensions you want them to be in the final document. Resizing raster image leads to loss of quality. Furthermore I fin dit easier to keep font sizes consistent among plots with different sizes when I don’t have to resize the plot afterwards.

 

Note that pdf and Word don’t mix well.

 

Png works quite well for high quality graphics (when created at the desired dimensions).

 

Best regards,

 

Thierry

 

 

ir. Thierry Onkelinx

Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest

team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance

Kliniekstraat 25

1070 Anderlecht

Belgium

+ 32 2 525 02 51

+ 32 54 43 61 85

Thierry....@inbo.be

www.inbo.be

 

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.

~ Sir Ronald Aylmer Fisher

 

The plural of anecdote is not data.

~ Roger Brinner

 

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.

~ John Tukey

--

kw

unread,
Mar 21, 2012, 8:57:09 AM3/21/12
to ggp...@googlegroups.com, kw
Any suggestions for a resolution parameter? I haven't used the png() function before. I set the units to "in" and png() seems to demand a resolution.

Thanks again,
KW

Michael Griffiths

unread,
Mar 21, 2012, 8:59:42 AM3/21/12
to ggp...@googlegroups.com
Create the graphs as PNG files and insert into the document. ggsave is very easy and robust to use for this, or RStudio makes it painfully simple to save graphs as well.
 
There's nothing per se wrong with saving as a PNG file and then making the graph smaller (proportionally), but it can make the graph unreadable. Axes labels in particular are liable to become difficult to read and the mixed sizes will screw with the polished look of your report.
 
If you want to edit / annotate the graphs you can save as PDF and then edit in e.g. Illustrator.
 
Also, don't use png(); use ggsave, e.g.
 
ggsave(filename="mygraph.png",plot=plot)
 
Full syntax is
 

ggsave(filename=default_name(plot), plot = last_plot(), device=default_device(filename), path = NULL, scale=1, width=par("din")[1], height=par("din")[2], dpi=300, keep = plot$options$keep, drop = plot$options$drop, ...)



Keith Weintraub

unread,
Mar 21, 2012, 9:04:54 AM3/21/12
to Michael Griffiths, ggp...@googlegroups.com
I have one plot that uses viewports. Does ggsave "play nice" with that?

The rest of my plots should work out fine.

Thanks,
KW

--

Jean-Olivier Irisson

unread,
Mar 21, 2012, 9:36:20 AM3/21/12
to Keith Weintraub, Michael Griffiths, ggp...@googlegroups.com
On 2012-Mar-21, at 14:04 , Keith Weintraub wrote:
>
> I have one plot that uses viewports. Does ggsave "play nice" with that?

It should.


Regarding the resolution, about which you asked earlier, it all depends on how the document will be used. Journals often require a resolution for raster images (most of the time 600dpi). For printing on a regular printer, 300dpi is usually fine. To view the document on screen only, 150dpi should be enough.


Overall, the strategy to adopt unfortunately depends on many factors (which software is used, on what platform, what is the purpose of the document, what are the quality requirements). My general advice would be:

- if it is for a quick job, with no particular requirements, use 150 dpi PNGs at the final size they should have on the document; they will be compatible with everything and shouldn't weight too much

- if you want quality, create PDFs and insert them in the final layout in Pages only (Word on windows does not play nice). I would also create them at 1.5 or 2 times the final size and increase the font size to compensate for the later shrinking; this makes the lines (in particular grid lines) thiner and usually looks better in a high quality document. You could also alter the theme to make grid lines and other elements thinner. Of course, this might juste be a matter of personal preference ;)

Jean-Olivier Irisson
---
Observatoire Océanologique
Station Zoologique, B.P. 28, Chemin du Lazaret
06230 Villefranche-sur-Mer
Tel: +33 04 93 76 38 04
Mob: +33 06 21 05 19 90
http://jo.irisson.com/

Sean O'Riordain

unread,
Mar 21, 2012, 11:59:14 AM3/21/12
to Jean-Olivier Irisson, Keith Weintraub, Michael Griffiths, ggp...@googlegroups.com
On Windows when putting pictures in MS-Word documents you have the extra choice of the Windows metafile format which (correct me if I'm wrong) is a vector format which works well in MS-Word.

On windows refer
?win.metafile

Although it is of course better if you do not re-size the images after they are generated, but put them directly into your document.

Personally I use latex and the tikz() device - but it's not to everybodys taste.

Kind regards,
Sean O'Riordain
Dublin

David Stevens

unread,
Mar 21, 2012, 12:29:47 PM3/21/12
to ggp...@googlegroups.com
I use word when I have to for clients and find that the metafile format works very well (also in FrameMaker, which I much prefer). I also insert the graphics as references to the file on disk rather than inserting the graphic to keep the word filesize reasonable. If it's necessary to resize the graphic, make sure to keep the aspect ratio the same as the original and you'll get a crisp figure at whatever size you need.

There is a caveat - if your figure has a lot of points/lines etc., it's often better to use a raster format created at the final size because word redraws the vector files every time you resize/scroll and this can cause annoying delays in editing. This is necessary also if you need transparent shading or lines as the metafile format doesn't support transparency in colors.

Finally, if you will create a pdf from the word file, be sure to use a pdf printer rather than the word 'save as pdf' feature because the word version messes up such things as rotation of labels, and some others, probably because MS wants you to use their pdf rival.

David Stevens
-- 
David K Stevens, P.E., Ph.D., Professor
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david....@usu.edu


Reply all
Reply to author
Forward
0 new messages