- R Graphs Cookbook Second Edition
- Jaynal Abedin Hrishi V. Mittal
- 366字
- 2021-08-05 17:30:33
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
arguments. In the example mentioned, we used mai
, which takes a vector values in inches, whereas mar
takes a vector of numerical values in terms of the number of lines of margins. It is better to use mar
or mai
because they adjust the figure margins irrespective of the figure or plot size.
We can also set an outer margin that is set to zero by default. This margin is useful if we wish to contain the entire graph including axis labels within a box, as we saw in an earlier recipe. Like figure margins, outer margins can be set in inches with omi
or in number of lines of text using oma
.
R Graphics by Paul Murrell (CRC Press) is an excellent reference with visual explanations of how margins work in R. See the book's homepage for more details at http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html.
This talk by Paul Murrell also contains figures from the book, explaining the same concepts: http://www.stat.auckland.ac.nz/~paul/Talks/Rgraphics.pdf.
See also
We will come across examples of figure margin settings in some of the recipes in the following chapters.
- Learning SQL Server Reporting Services 2012
- Aftershot Pro:Non-destructive photo editing and management
- 電腦組裝與維修從入門到精通(第2版)
- 3ds Max Speed Modeling for 3D Artists
- VCD、DVD原理與維修
- Hands-On Machine Learning with C#
- 嵌入式系統中的模擬電路設計
- CC2530單片機技術與應用
- SiFive 經典RISC-V FE310微控制器原理與實踐
- RISC-V處理器與片上系統設計:基于FPGA與云平臺的實驗教程
- Hands-On Deep Learning for Images with TensorFlow
- 單片機項目設計教程
- Arduino項目案例:游戲開發
- 微控制器的應用
- 單片機原理及應用