R Plots Par Average ratng: 9,9/10 4714 votes

There are 2 margin areas in base R plots: margin and oma.You can control their size calling the par function before your plot and giving the corresponding arguments. Mar for margin. Oma for outer margin area. For both arguments, you must give four values giving the desired space in the bottom, left, top and right part of the chart respectively. The R plot function allows you to create a plot passing two vectors (of the same length), a dataframe, matrix or even other objects, depending on its class or the input type. We are going to simulate two random normal variables called x and y and use them in almost all the plot examples.


The aim of this article is to show how to modify the title of graphs (main title and axis titles) in R software. There are two possible ways to do that :

  • Directly by specifying the titles to the plotting function (ex : plot() ). In this case titles are modified during the creation of plot.
  • the title() function can also be used. It adds titles on an existing plot.

The following arguments can be used :

  • main: the text for the main title
  • xlab: the text for the x axis label
  • ylab: the text for y axis title
  • sub: sub-title; It’s placed at the bottom of x-axis

R Plot Par Mar

The following parameters can be used to change the colors :

  • col.main: color the main title
  • col.lab: color of the axis titles (x and y axis)
  • col.sub: color of the sub-title

Note that, the different colors available in R software are described here.

The graphical parameters to use for customizing the font of the titles are :

  • font.main: font style for the main title
  • font.lab: font style for the axis titles
  • font.sub: font style for the sub-title

The value of these arguments should be an integer.

The possible values for the font style are :

  • 1: normal text
  • 2: bold
  • 3: italic
  • 4: bold and italic
  • 5 : Symbol font

Use the R code below to create a plot title with bold and italic font style.

font size can be modified using the graphical parameter : cex. The default value is 1. If cex value is inferior to 1, then the text size is decreased. Conversely, any value of cex greater than 1 can increase the font size.

The following arguments can be used to change the font size :

  • cex.main : text size for main title
  • cex.lab : text size for axis title
  • cex.sub : text size of the sub-title

An example is shown below :

title() can be also used to add titles to a graph.

A simplified format is :

Example of usage

Note that, the R par() function can be used to change the color, font style and size for the graph titles. The modifications done by the par() function are called ‘permanent modification’ because they are applied to all the plots generated under the current R session.

Read more on par() by clicking here.

This analysis has been performed using R statistical software (ver. 3.1.0).


Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.
Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.
Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!



Recommended for You!




More books on R and data science

Recommended for you

This section contains best data science and self-development resources to help you on your path.

Coursera - Online Courses and Specialization

Data science

  • Course: Machine Learning: Master the Fundamentals by Standford
  • Specialization: Data Science by Johns Hopkins University
  • Specialization: Python for Everybody by University of Michigan
  • Courses: Build Skills for a Top Job in any Industry by Coursera
  • Specialization: Master Machine Learning Fundamentals by University of Washington
  • Specialization: Statistics with R by Duke University
  • Specialization: Software Development in R by Johns Hopkins University
  • Specialization: Genomic Data Science by Johns Hopkins University

Popular Courses Launched in 2020

  • Google IT Automation with Python by Google
  • AI for Medicine by deeplearning.ai
  • Epidemiology in Public Health Practice by Johns Hopkins University
  • AWS Fundamentals by Amazon Web Services

Trending Courses

  • The Science of Well-Being by Yale University
  • Google IT Support Professional by Google
  • Python for Everybody by University of Michigan
  • IBM Data Science Professional Certificate by IBM
  • Business Foundations by University of Pennsylvania
  • Introduction to Psychology by Yale University
  • Excel Skills for Business by Macquarie University
  • Psychological First Aid by Johns Hopkins University
  • Graphic Design by Cal Arts

Books - Data Science

Plots

Our Books

  • Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
  • Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
  • Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
  • R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
  • GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
  • Network Analysis and Visualization in R by A. Kassambara (Datanovia)
  • Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
  • Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)

Others

  • R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
  • Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
  • Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
  • Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
  • An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
  • Deep Learning with R by François Chollet & J.J. Allaire
  • Deep Learning with Python by François Chollet


Want to Learn More on R Programming and Data Science?
Follow us by EmailOn Social Networks:

Get involved :
Click to follow us on Facebook and Google+ :
Comment this article by clicking on 'Discussion' button (top-right position of this page)
  • Related Questions & Answers
  • Selected Reading
R ProgrammingServer Side ProgrammingProgramming

When we use par(mfrow), we define the number of plots we want to draw on the plot window and when we draw all the necessary plots then starts again with the first plot. For example, if we set par(mfrow) to (2,2) then we will have four plots on the plot window but if we want to create one plot on the plot window then it does not work, it will show a small plot on the upper left side. To deal with the problem, we can set par(mfrow) to (1,1).

Example

Output

Creating fifth plot which we want to fit the whole plot window −

Example

Output

R Plots Par

Changing par(mfrow) to make the fifth plot on the whole plot window −

Par Mar In R

Example

R Plot Par Margins

Output

Coments are closed
Scroll to top