The following is a template that I usually start with when producing figures for publication. It allows me to control:
- The overall size of the figure (in inches) (WIDTH, HEIGHT)
- The layout of figure subplots (using the layout() function) (LO)
- The resolution of the figure (for a .png file) (RESO)
I define margins (mar, oma) in terms of point size (ps), since this relates to the height of text, which allows of control of axis labeling. By defining the outer margins (OMA) and point size (PS) before calling layout, you will have these margins incorporated. Then, by running the x11() device (after the #), you can check your figure layout with layout.show(n):
I learned recently that the layout() function will adjust the character expansion size (par()$cex) depending on how your device is split up. For that reason, I usually include another line of code resetting par(cex=1) before proceeding with individual plots.
Finally, the three different device types included in the template are:
- x11(), for initial tweaking of the layout and general functionality of the plotting code
- png(), for producing a compact figure useful in pasting into Word documents, and for cases where the figure contains a lot of information and would be slow to loading as a .pdf
- pdf(), for a vector-based figure that is fully scalable / zoomable. When not too big, these figures look the best, and can also be embedded in LaTeX documents
Figure template: