Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Setting graph margins and dimensions


In this recipe, we will learn how to adjust graph margins and dimensions.

Getting ready

All you need to try out in this recipe is to run R and type the recipe in the command prompt. You can also choose to save the recipe as a script so that you can use it again later on.

How to do it...

We can use the fin and pin arguments of the par() command to set the figure region and plot dimensions:

par(fin=c(6,6),
pin=c(4,4))

We can use the mai and omi arguments to adjust the inner and outer margins, respectively:

par(mai=c(1,1,1,1),
omi=c(0.1,0.1,0.1,0.1))

How it works...

All the mentioned arguments accept values in inches as a pair of width and height values. The default values for fin and pin are approximately 7 x 7 and 5.75 x 5.15. We have to be careful not to specify higher values for pin than fin, or we would get an error.

Adjusting fin and pin is one way of setting the figure margins that contain the axis annotations and labels. Another way is to use the mai or mar...